public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* When is it OK to pass NULLs to the 2nd and 3rd args of execve()?
@ 2021-04-09 16:53 Peng Yu
  2021-04-09 17:03 ` tomas
  2021-04-09 22:06 ` Mike Frysinger
  0 siblings, 2 replies; 5+ messages in thread
From: Peng Yu @ 2021-04-09 16:53 UTC (permalink / raw)
  To: libc-help

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-09 22:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 16:53 When is it OK to pass NULLs to the 2nd and 3rd args of execve()? Peng Yu
2021-04-09 17:03 ` tomas
2021-04-09 17:20   ` Peng Yu
2021-04-09 17:32     ` tomas
2021-04-09 22:06 ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).