From 3941f59cb92c262e98b3e554baf4b8921113e1d1 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 6 Dec 2009 23:19:49 +0100 Subject: [PATCH] prognam: Add diagnostic. --- ChangeLog | 5 +++++ lib/progname.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 90d6eb03c..be28f93c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-12-06 Bruno Haible + + * lib/progname.c: Include stdio.h, stdlib.h. + (set_program_name): Reject a NULL argument. + 2009-12-05 Eric Blake pipe2-safer: new module diff --git a/lib/progname.c b/lib/progname.c index c8660c941..2e82ac9ed 100644 --- a/lib/progname.c +++ b/lib/progname.c @@ -23,6 +23,8 @@ #include "progname.h" #include /* get program_invocation_name declaration */ +#include +#include #include @@ -44,6 +46,16 @@ set_program_name (const char *argv0) const char *slash; const char *base; + /* Sanity check. POSIX requires the invoking process to pass a non-NULL + argv[0]. */ + if (argv0 == NULL) + { + /* It's a bug in the invoking program. Help diagnosing it. */ + fputs ("A NULL argv[0] was passed through an exec system call.\n", + stderr); + abort (); + } + slash = strrchr (argv0, '/'); base = (slash != NULL ? slash + 1 : argv0); if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0) -- 2.11.0