Bug 229

Summary: hush does not throw syntax error when reaching EOF with invalid code
Product: Busybox Reporter: Mike Frysinger <vapier>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: enhancement CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:
Attachments: Fix

Description Mike Frysinger 2009-03-28 19:16:27 UTC
if hush reaches EOF on an invalid script, it does not throw an error but rather exits quietly

i imagine this is because it wants to be nice when running in interactive mode, but bash will throw up on you in this case, so we might as well too

example:
$ echo '(' > test.sh
$ bash ./test.sh ; echo $?
./test.sh: line 2: syntax error: unexpected end of file
2
$ hush ./test.sh ; echo $?
0

same behavior can be seen in interactive mode

even worse, we segfault when using -c:
$ hush -c '('
Segmentation fault

i think this is the fix for that case:
--- shell/hush.c      (revision 25863)
+++ shell/hush.c      (working copy)
@@ -1024,7 +1024,9 @@
  */
 static int static_get(struct in_str *i)
 {
-       int ch = *i->p++;
+       int ch;
+       if (!i->p) return EOF;
+       ch = *i->p++;
        if (ch == '\0') return EOF;
        return ch;
 }
Comment 1 Denys Vlasenko 2009-05-02 15:16:29 UTC
Created attachment 285 [details]
Fix

Try attached patch please
Comment 2 Denys Vlasenko 2009-05-02 15:19:16 UTC
Pushed to git:

[master b1cfc45] hush: fix handling of unterminated subshell: (<eof>. Fixes bug 229.