[git commit master] hush: handle empty execs

Mike Frysinger vapier at gentoo.org
Sun Oct 18 05:15:36 UTC 2009


commit: http://git.busybox.net/busybox/commit/?id=28736c36ca6a73864324296117ce26c9a23066dd
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

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 at gentoo.org>
---
 shell/hush.c                                |    6 ++++++
 shell/hush_test/hush-psubst/emptytick.right |   14 ++++++++++++++
 shell/hush_test/hush-psubst/emptytick.tests |   16 ++++++++++++++++
 3 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 shell/hush_test/hush-psubst/emptytick.right
 create mode 100755 shell/hush_test/hush-psubst/emptytick.tests

diff --git a/shell/hush.c b/shell/hush.c
index 2d333d7..1d2826d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -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
index 0000000..d4b70c5
--- /dev/null
+++ b/shell/hush_test/hush-psubst/emptytick.right
@@ -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
index 0000000..af3a183
--- /dev/null
+++ b/shell/hush_test/hush-psubst/emptytick.tests
@@ -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 $?
-- 
1.6.3.3



More information about the busybox-cvs mailing list