hush: handle empty execs
authorMike Frysinger <vapier@gentoo.org>
Sun, 18 Oct 2009 05:11:45 +0000 (01:11 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sun, 18 Oct 2009 05:15:36 +0000 (01:15 -0400)
Sometimes variable expansions yield empty strings, and if they happen to
be a command someone wants to run like `$foo`, then hush currently
segfaults.  So handle `` and $().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
shell/hush.c
shell/hush_test/hush-psubst/emptytick.right [new file with mode: 0644]
shell/hush_test/hush-psubst/emptytick.tests [new file with mode: 0755]

index 2d333d73103a4901ce57119601b0d035df1c4fb0..1d2826d9a5ef9eb50d6b510aa08569d50f1cff1d 100644 (file)
@@ -3895,6 +3895,12 @@ static NOINLINE int run_pipe(struct pipe *pi)
                        argv_expanded = expand_strvec_to_strvec(argv + command->assignment_cnt);
                }
 
+               /* if someone gives us an empty string: ``, $(), ... */
+               if (!argv_expanded[0]) {
+                       debug_leave();
+                       return 0;
+               }
+
                x = find_builtin(argv_expanded[0]);
 #if ENABLE_HUSH_FUNCTIONS
                funcp = NULL;
diff --git a/shell/hush_test/hush-psubst/emptytick.right b/shell/hush_test/hush-psubst/emptytick.right
new file mode 100644 (file)
index 0000000..d4b70c5
--- /dev/null
@@ -0,0 +1,14 @@
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
diff --git a/shell/hush_test/hush-psubst/emptytick.tests b/shell/hush_test/hush-psubst/emptytick.tests
new file mode 100755 (executable)
index 0000000..af3a183
--- /dev/null
@@ -0,0 +1,16 @@
+true;  ``; echo $?
+false; ``; echo $?
+true;  `""`; echo $?
+false; `""`; echo $?
+true;  `     `; echo $?
+false; `     `; echo $?
+
+true;  $(); echo $?
+false; $(); echo $?
+true;  $(""); echo $?
+false; $(""); echo $?
+true;  $(     ); echo $?
+false; $(     ); echo $?
+
+true;  exec ''; echo $?
+false; exec ''; echo $?