svn commit: trunk/busybox/shell

vda at busybox.net vda at busybox.net
Wed May 9 15:16:09 PDT 2007


Author: vda
Date: 2007-05-09 15:16:08 -0700 (Wed, 09 May 2007)
New Revision: 18597

Log:
msh: fix obscure case with backticks and closed fd 1



Modified:
   trunk/busybox/shell/msh.c


Changeset:
Modified: trunk/busybox/shell/msh.c
===================================================================
--- trunk/busybox/shell/msh.c	2007-05-09 21:57:23 UTC (rev 18596)
+++ trunk/busybox/shell/msh.c	2007-05-09 22:16:08 UTC (rev 18597)
@@ -2546,7 +2546,7 @@
 				interactive = 0;
 				if (pin == NULL) {
 					close(0);
-					open(bb_dev_null, O_RDONLY);
+					xopen(bb_dev_null, O_RDONLY);
 				}
 				_exit(execute(t->left, pin, pout, FEXEC));
 			}
@@ -2823,12 +2823,12 @@
 #endif
 
 	if (pin != NULL) {
-		dup2(pin[0], 0);
-		closepipe(pin);
+		xmove_fd(pin[0], 0);
+		if (pin[1] != 0) close(pin[1]);
 	}
 	if (pout != NULL) {
-		dup2(pout[1], 1);
-		closepipe(pout);
+		xmove_fd(pout[1], 1);
+		if (pout[1] != 1) close(pout[0]);
 	}
 
 	iopp = t->ioact;
@@ -4166,8 +4166,13 @@
 		if (ourtrap[j] && signal(j, SIG_IGN) != SIG_IGN)
 			signal(j, SIG_DFL);
 
-	dup2(pf[1], 1);
-	closepipe(pf);
+	/* Testcase where below checks are needed:
+	 * close stdout & run this script:
+	 *  files=`ls`
+	 *  echo "$files" >zz
+	 */
+	xmove_fd(pf[1], 1);
+	if (pf[0] != 1) close(pf[0]);
 
 	argument_list[0] = (char *) DEFAULT_SHELL;
 	argument_list[1] = (char *) "-c";



More information about the busybox-cvs mailing list