]> mj.ucw.cz Git - libucw.git/commitdiff
setproctitle: Copy all arguments in setproctitle_init()
authorMartin Mares <mj@ucw.cz>
Wed, 18 Jul 2012 16:46:09 +0000 (18:46 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 18 Jul 2012 16:46:09 +0000 (18:46 +0200)
Otherwise, values of command-line arguments, which are not explicitly
copied, can be corrupted by setproctitle().

ucw/process.h
ucw/proctitle.c

index 2c7802379c6b5eec525fd950e34ff27253b3cf16..b995cf573f3d3dfac4631f3f5804edfce186101c 100644 (file)
@@ -12,6 +12,7 @@
 
 /* proctitle.c */
 
+// Must be called before parsing of arguments
 void setproctitle_init(int argc, char **argv);
 void setproctitle(const char *msg, ...) FORMAT_CHECK(printf,1,2);
 char *getproctitle(void);
index 8810b0bfceb1b16200a702538f726f8a910dc217..82a0b8eda3433b6d5c271535eadacb3400f6b961 100644 (file)
@@ -53,8 +53,12 @@ setproctitle_init(int argc, char **argv)
     if (spt_end+1 == oldenv[i])
       spt_end = oldenv[i] + strlen(oldenv[i]);
 
+  /* Copy all arguments */
+  for (i=0; i<argc; i++)
+    argv[i] = xstrdup(argv[i]);
+
   /* Recalculate program_invocation_name, otherwise syslog() will be confused. */
-  char *name = xstrdup(argv[0]);
+  char *name = argv[0];
   program_invocation_name = name;
   char *p = strrchr(name, '/');
   if (p)