diff options
author | jdp <jdp@FreeBSD.org> | 2000-12-04 01:45:57 +0000 |
---|---|---|
committer | jdp <jdp@FreeBSD.org> | 2000-12-04 01:45:57 +0000 |
commit | 2a2576da75de85b096219447c61387c1af59093b (patch) | |
tree | 5ff6534e19ee039fb3043c49ec02e3254cbceee6 | |
parent | 588932041e79922c56d2f2d9740050a5858763b5 (diff) | |
download | FreeBSD-src-2a2576da75de85b096219447c61387c1af59093b.zip FreeBSD-src-2a2576da75de85b096219447c61387c1af59093b.tar.gz |
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.
-rw-r--r-- | lib/libc/gen/setproctitle.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c index 7d4fdae..6b71d53 100644 --- a/lib/libc/gen/setproctitle.c +++ b/lib/libc/gen/setproctitle.c @@ -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) |