From 6d71b488b607c79fb49f8d14f22aedbf1771f6ba Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 5 Feb 2015 11:17:24 -0700 Subject: [PATCH] Call setprogname("sudo") if getprogname() returns NULL or the empty string. --- lib/util/progname.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/util/progname.c b/lib/util/progname.c index ed81741c8..1f4bba8a1 100644 --- a/lib/util/progname.c +++ b/lib/util/progname.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Todd C. Miller + * Copyright (c) 2013-2015 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -42,10 +42,19 @@ void initprogname(const char *name) { # ifdef HAVE_SETPROGNAME + const char *progname; + + /* Fall back on "name" if getprogname() returns an empty string. */ + if ((progname = getprogname()) != NULL && *progname != '\0') + name = progname; + /* Check for libtool prefix and strip it if present. */ - name = getprogname(); if (name[0] == 'l' && name[1] == 't' && name[2] == '-' && name[3] != '\0') - setprogname(name + 3); + name += 3; + + /* Update internal progname if needed. */ + if (name != progname) + setprogname(name); # endif return; } @@ -60,15 +69,17 @@ initprogname(const char *name) # ifdef HAVE___PROGNAME extern const char *__progname; - progname = __progname; -# else + if (__progname != NULL && *__progname != '\0') + progname = __progname; + else +# endif if ((progname = strrchr(name, '/')) != NULL) { progname++; } else { progname = name; } -#endif + /* Check for libtool prefix and strip it if present. */ if (progname[0] == 'l' && progname[1] == 't' && progname[2] == '-' && progname[3] != '\0') progname += 3; -- 2.40.0