fix new environment always being null with execle

the va_arg call for the argv[]-terminating null pointer was missing,
so this pointer was being wrongly used as the environment pointer.

issue reported by Timo Teräs. proposed patch slightly modified to
simplify the resulting code.
This commit is contained in:
Rich Felker
2013-10-03 10:16:01 -04:00
parent 23b8e3bc95
commit 2b2aff37ac

View File

@ -14,9 +14,8 @@ int execle(const char *path, const char *argv0, ...)
char **envp;
va_start(ap, argv0);
argv[0] = (char *)argv0;
for (i=1; i<argc; i++)
for (i=1; i<=argc; i++)
argv[i] = va_arg(ap, char *);
argv[i] = NULL;
envp = va_arg(ap, char **);
return execve(path, argv, envp);
}