Weird trouble w/ Cargo + execve

Hi there, Guys.
i need some advice of Yours. i've tried to run cargo command w/ execve syscall, but cargo can't consume static-sized array of args..

bash> cargo clean ""
error: unrecognized subcommand ''

how to prevent cargo to react on those empty CStrings ???

Thanks a lot in Advance.

match execve ( &c_str ( &app_name), &args[0..cnt], &env ) {
Err(e) => {logErr(e );},
_ => {}
};
seems to work..

It's a strange request -- I think most programs will try to deal with an empty argument differently than it would without that argument at all.

In this particular case, ["cargo", "clean", "--"] would work to pad it to 3 arguments, but you couldn't go any further that way.

argv passed to execve is a pointer to an array of pointers. So just set the pointer in the slot after the last argument to null instead of pointing to an empty string. Then any further elements will be ignored.

2 Likes