When recording the original arguments, stop short if we encounter
a NULL argument. Some programs change the contents of the argv array, typically to remove some special arguments. They shorten argv by storing a NULL where an argument pointer used to be. Such programs core dumped if they called setproctitle(), because it would try to apply strlen() to a NULL pointer.
This commit is contained in:
parent
bd1c746647
commit
882cdc116d
@ -126,6 +126,16 @@ setproctitle(const char *fmt, ...)
|
||||
oargc = ps_strings->ps_nargvstr;
|
||||
oargv = ps_strings->ps_argvstr;
|
||||
for (i = len = 0; i < oargc; i++) {
|
||||
/*
|
||||
* The program may have scribbled into its
|
||||
* argv array, e.g., to remove some arguments.
|
||||
* If that has happened, break out before
|
||||
* trying to call strlen on a NULL pointer.
|
||||
*/
|
||||
if (oargv[i] == NULL) {
|
||||
oargc = i;
|
||||
break;
|
||||
}
|
||||
snprintf(obuf + len, sizeof(obuf) - len, "%s%s",
|
||||
len ? " " : "", oargv[i]);
|
||||
if (len)
|
||||
|
Loading…
x
Reference in New Issue
Block a user