When is it OK to pass NULLs to the 2nd and 3rd args of execve()?
Peng Yu
pengyu.ut@gmail.com
Fri Apr 9 16:53:39 GMT 2021
Hi,
I am wondering when (all possible legitimate cases) it is OK to pass
NULLs to execve's 2nd and 3rd args.
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
if(execve(argv[1], NULL, NULL) == -1) {
perror("execvp()");
return 1;
}
return 0;
}
I tried the above program. It works when it is called with `/bin/sh`.
My guess is that when the program being exec'ed don't use its args and
envs, then then 2nd and 3rd args of execve() can be NULLs. Could
anybody correct me if I am wrong?
--
Regards,
Peng
More information about the Libc-help
mailing list