Bug 229 - hush does not throw syntax error when reaching EOF with invalid code
Summary: hush does not throw syntax error when reaching EOF with invalid code
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: PC Linux
: P5 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-28 19:16 UTC by Mike Frysinger
Modified: 2009-05-25 23:53 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Fix (1.14 KB, patch)
2009-05-02 15:16 UTC, Denys Vlasenko
Details

Note You need to log in before you can comment on or make changes to this bug.
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.