From 7dad5f25591de682c452c3fc39ffe2fa11e21491 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 13 Oct 2016 14:59:10 -0700 Subject: [PATCH] getprogname: IBM z/OS: avoid NULL-dereference * lib/getprogname.c (getprogname) [__MVS__]: Don't dereference NULL upon strdup failure. --- ChangeLog | 6 ++++++ lib/getprogname.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f94feb1..5b5f81d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-10-13 Jim Meyering + + getprogname: IBM z/OS: avoid NULL-dereference + * lib/getprogname.c (getprogname) [__MVS__]: Don't dereference NULL + upon strdup failure. + 2016-10-12 Jim Meyering test-stdint: use _GL_VERIFY rather than "verify" for some tests diff --git a/lib/getprogname.c b/lib/getprogname.c index a19612a..0e8d963 100644 --- a/lib/getprogname.c +++ b/lib/getprogname.c @@ -104,7 +104,9 @@ getprogname (void) { if (token > 0 && buf.ps_pid == pid) { - p = strdup (last_component (buf.ps_pathptr)); + char *s = strdup (last_component (buf.ps_pathptr)); + if (s) + p = s; break; } } -- 2.7.4