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>
This commit is contained in:
Mike Frysinger 2009-10-18 01:11:45 -04:00
parent 69d9edc6f8
commit 28736c36ca
3 changed files with 36 additions and 0 deletions

View 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;

View File

@ -0,0 +1,14 @@
0
0
0
0
0
0
0
0
0
0
0
0
0
0

View File

@ -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 $?