]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Duplicate setprogname argument
authorRobert Millan <rmh@aybabtu.com>
Thu, 30 Mar 2006 11:14:56 +0000 (11:14 +0000)
committerGuillem Jover <guillem@hadrons.org>
Tue, 6 May 2008 05:55:56 +0000 (08:55 +0300)
For some reason, accessing the argv vector directly may cause SIGSEV.

src/progname.c

index 77776581fa032a5568fff7d5884c5d81667e813c..e422b5e15b574fc0d5d2fba34685c8df5601fbe7 100644 (file)
   Rejected in glibc (http://sourceware.org/ml/libc-alpha/2006-03/msg00125.html)
 */
 
-#include <bsd/stdlib.h>
+#include <bsd/stdlib.h>                /* progname, strdup */
+#include <string.h>            /* free */
 
-static char *__progname = NULL;
+char *__progname = NULL;
 
 char *
 getprogname ()
@@ -32,5 +33,10 @@ getprogname ()
 void
 setprogname (char *new)
 {
-  __progname = new;
+  /* For some reason, accessing the argv vector directly may cause SIGSEV.  Let's copy it to avoid trouble. */
+
+  if (__progname != NULL)
+    free (__progname);
+
+  __progname = strdup (new);
 }