On Thu, Oct 13, 2016 at 1:10 PM, Jim Meyering <[email protected]> wrote: > On Thu, Oct 13, 2016 at 1:50 AM, Pádraig Brady <[email protected]> wrote: >> On 13/10/16 02:43, Daniel Richard G. wrote: >>> On Wed, 2016 Oct 12 11:04+0100, Pádraig Brady wrote: >>>> >>>> You only want to strdup once. >>>> So you could use a static to track that as is done in the AIX case. >>> >>> Ah, I see, the program name never changes. >>> >>>> You can call free(NULL), so the last 3 ifs are redundant. >>> >>> Revised patch is tested and attached. >> >> Pushed at: >> http://git.svh.gnu.org/gitweb/?p=gnulib.git;a=commit;h=d75cbb3 > > Thanks. > This will be pulled into grep soon.
I've pushed this additional fix:
From 7dad5f25591de682c452c3fc39ffe2fa11e21491 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> 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 <[email protected]> + + getprogname: IBM z/OS: avoid NULL-dereference + * lib/getprogname.c (getprogname) [__MVS__]: Don't dereference NULL + upon strdup failure. + 2016-10-12 Jim Meyering <[email protected]> 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
