aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-10-18 01:11:45 -0400
committerMike Frysinger <vapier@gentoo.org>2009-10-18 01:15:36 -0400
commit28736c36ca6a73864324296117ce26c9a23066dd (patch)
tree932f02ded50c8df7db9a7eea3063c2ed6c841fc1
parent69d9edc6f8387ed0ec4742a5de895b22b3910818 (diff)
downloadbusybox-w32-28736c36ca6a73864324296117ce26c9a23066dd.tar.gz
busybox-w32-28736c36ca6a73864324296117ce26c9a23066dd.tar.bz2
busybox-w32-28736c36ca6a73864324296117ce26c9a23066dd.zip
hush: handle empty execs
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>
-rw-r--r--shell/hush.c6
-rw-r--r--shell/hush_test/hush-psubst/emptytick.right14
-rwxr-xr-xshell/hush_test/hush-psubst/emptytick.tests16
3 files changed, 36 insertions, 0 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 2d333d731..1d2826d9a 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3895,6 +3895,12 @@ static NOINLINE int run_pipe(struct pipe *pi)
3895 argv_expanded = expand_strvec_to_strvec(argv + command->assignment_cnt); 3895 argv_expanded = expand_strvec_to_strvec(argv + command->assignment_cnt);
3896 } 3896 }
3897 3897
3898 /* if someone gives us an empty string: ``, $(), ... */
3899 if (!argv_expanded[0]) {
3900 debug_leave();
3901 return 0;
3902 }
3903
3898 x = find_builtin(argv_expanded[0]); 3904 x = find_builtin(argv_expanded[0]);
3899#if ENABLE_HUSH_FUNCTIONS 3905#if ENABLE_HUSH_FUNCTIONS
3900 funcp = NULL; 3906 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 000000000..d4b70c58a
--- /dev/null
+++ b/shell/hush_test/hush-psubst/emptytick.right
@@ -0,0 +1,14 @@
10
20
30
40
50
60
70
80
90
100
110
120
130
140
diff --git a/shell/hush_test/hush-psubst/emptytick.tests b/shell/hush_test/hush-psubst/emptytick.tests
new file mode 100755
index 000000000..af3a1836c
--- /dev/null
+++ b/shell/hush_test/hush-psubst/emptytick.tests
@@ -0,0 +1,16 @@
1true; ``; echo $?
2false; ``; echo $?
3true; `""`; echo $?
4false; `""`; echo $?
5true; ` `; echo $?
6false; ` `; echo $?
7
8true; $(); echo $?
9false; $(); echo $?
10true; $(""); echo $?
11false; $(""); echo $?
12true; $( ); echo $?
13false; $( ); echo $?
14
15true; exec ''; echo $?
16false; exec ''; echo $?