changeset 955:144d5ba7d410

Replace users of xexec(toys.optargs) with xexec_optargs(0) to avoid free/reuse bug during argument parsing.
author Rob Landley <rob@landley.net>
date Thu, 18 Jul 2013 18:20:03 -0500
parents 1cf9c28012a7
children caa05719070f
files toys/other/chroot.c toys/other/netcat.c toys/other/setsid.c toys/other/taskset.c toys/other/unshare.c toys/pending/klogd.c toys/posix/nice.c toys/posix/nohup.c toys/posix/time.c
diffstat 9 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/toys/other/chroot.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/other/chroot.c	Thu Jul 18 18:20:03 2013 -0500
@@ -18,6 +18,8 @@
 void chroot_main(void)
 {
   char *binsh[] = {"/bin/sh", "-i", 0};
+
   if (chdir(*toys.optargs) || chroot(".")) perror_exit("%s", *toys.optargs);
-  xexec(toys.optargs[1] ? toys.optargs+1 : binsh);
+  if (toys.optargs[1]) xexec_optargs(1);
+  else xexec(binsh);
 }
--- a/toys/other/netcat.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/other/netcat.c	Thu Jul 18 18:20:03 2013 -0500
@@ -187,7 +187,7 @@
   set_alarm(0);
 
   if (CFG_NETCAT_LISTEN && (toys.optflags&(FLAG_L|FLAG_l) && toys.optc))
-    xexec(toys.optargs);
+    xexec_optargs(0);
 
   // Poll loop copying stdin->socket and socket->stdout.
   for (;;) {
--- a/toys/other/setsid.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/other/setsid.c	Thu Jul 18 18:20:03 2013 -0500
@@ -24,5 +24,5 @@
     setpgid(0,0);
     tcsetpgrp(0, getpid());
   }
-  xexec(toys.optargs);
+  xexec_optargs(0);
 }
--- a/toys/other/taskset.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/other/taskset.c	Thu Jul 18 18:20:03 2013 -0500
@@ -90,7 +90,7 @@
   if (!(toys.optflags & FLAG_p)) {
     if (toys.optc < 2) error_exit("Needs 2 args");
     do_taskset(getpid(), 1);
-    xexec(toys.optargs+1);
+    xexec_optargs(1);
   } else {
     char *c;
     pid_t pid = strtol(toys.optargs[toys.optc-1], &c, 10);
--- a/toys/other/unshare.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/other/unshare.c	Thu Jul 18 18:20:03 2013 -0500
@@ -35,5 +35,5 @@
 
   if(unshare(f)) perror_exit("failed");
 
-  xexec(toys.optargs);
+  xexec_optargs(0);
 }
--- a/toys/pending/klogd.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/pending/klogd.c	Thu Jul 18 18:20:03 2013 -0500
@@ -23,7 +23,7 @@
 
 #define FOR_klogd
 #include "toys.h"
-#include <signal.h>
+
 GLOBALS(
   long level;
   int fd;
--- a/toys/posix/nice.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/posix/nice.c	Thu Jul 18 18:20:03 2013 -0500
@@ -34,5 +34,5 @@
   errno = 0;
   if (nice(TT.priority)==-1 && errno) perror_exit("Can't set priority");
 
-  xexec(toys.optargs);
+  xexec_optargs(0);
 }
--- a/toys/posix/nohup.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/posix/nohup.c	Thu Jul 18 18:20:03 2013 -0500
@@ -36,5 +36,5 @@
     close(0);
     open("/dev/null", O_RDONLY);
   }
-  xexec(toys.optargs);
+  xexec_optargs(0);
 }
--- a/toys/posix/time.c	Wed Jul 17 17:27:14 2013 -0500
+++ b/toys/posix/time.c	Thu Jul 18 18:20:03 2013 -0500
@@ -27,7 +27,7 @@
   struct timeval tv, tv2;
 
   gettimeofday(&tv, NULL);
-  if (!(pid = fork())) xexec(toys.optargs);
+  if (!(pid = fork())) xexec_optargs(0);
   else {
     int stat;
     struct rusage ru;