diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-29 20:43:26 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-29 20:43:26 +0200 |
commit | 0f018b30700989462de0a15b8285206d16170c1f (patch) | |
tree | f59fd946c2a00030fd2a65f45004da2b70eb136a | |
parent | a732898fdd9748b966da228ee8bbbc148c3c10c9 (diff) | |
download | busybox-w32-0f018b30700989462de0a15b8285206d16170c1f.tar.gz busybox-w32-0f018b30700989462de0a15b8285206d16170c1f.tar.bz2 busybox-w32-0f018b30700989462de0a15b8285206d16170c1f.zip |
hush: fix handling of empty heredoc EOF marker
function old new delta
parse_stream 2609 2634 +25
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash_test/ash-heredoc/heredoc_empty2.right | 4 | ||||
-rwxr-xr-x | shell/ash_test/ash-heredoc/heredoc_empty2.tests | 14 | ||||
-rw-r--r-- | shell/hush.c | 44 | ||||
-rw-r--r-- | shell/hush_test/hush-heredoc/heredoc_empty2.right | 4 | ||||
-rwxr-xr-x | shell/hush_test/hush-heredoc/heredoc_empty2.tests | 14 |
5 files changed, 63 insertions, 17 deletions
diff --git a/shell/ash_test/ash-heredoc/heredoc_empty2.right b/shell/ash_test/ash-heredoc/heredoc_empty2.right new file mode 100644 index 000000000..e32c6ea58 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc_empty2.right | |||
@@ -0,0 +1,4 @@ | |||
1 | OK1 | ||
2 | Ok:0 | ||
3 | OK2 | ||
4 | Ok:0 | ||
diff --git a/shell/ash_test/ash-heredoc/heredoc_empty2.tests b/shell/ash_test/ash-heredoc/heredoc_empty2.tests new file mode 100755 index 000000000..20fc35fe9 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc_empty2.tests | |||
@@ -0,0 +1,14 @@ | |||
1 | unset a | ||
2 | |||
3 | # Heredoc with empty delimiter | ||
4 | cat <<- "" | ||
5 | OK1 | ||
6 | |||
7 | echo Ok:$? | ||
8 | |||
9 | # Heredoc with empty delimiter | ||
10 | cat <<- "" | ||
11 | OK2 | ||
12 | |||
13 | |||
14 | echo Ok:$? | ||
diff --git a/shell/hush.c b/shell/hush.c index d0225edb9..0fae809b3 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -4001,24 +4001,34 @@ static char *fetch_till_str(o_string *as_string, | |||
4001 | ch = i_getch(input); | 4001 | ch = i_getch(input); |
4002 | if (ch != EOF) | 4002 | if (ch != EOF) |
4003 | nommu_addchr(as_string, ch); | 4003 | nommu_addchr(as_string, ch); |
4004 | if ((ch == '\n' || ch == EOF) | 4004 | if (ch == '\n' || ch == EOF) { |
4005 | && ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') | 4005 | check_heredoc_end: |
4006 | ) { | 4006 | if ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') { |
4007 | if (strcmp(heredoc.data + past_EOL, word) == 0) { | 4007 | if (strcmp(heredoc.data + past_EOL, word) == 0) { |
4008 | heredoc.data[past_EOL] = '\0'; | 4008 | heredoc.data[past_EOL] = '\0'; |
4009 | debug_printf_parse("parsed heredoc '%s'\n", heredoc.data); | 4009 | debug_printf_parse("parsed heredoc '%s'\n", heredoc.data); |
4010 | return heredoc.data; | 4010 | return heredoc.data; |
4011 | } | 4011 | } |
4012 | while (ch == '\n') { | 4012 | if (ch == '\n') { |
4013 | o_addchr(&heredoc, ch); | 4013 | /* This is a new line. |
4014 | prev = ch; | 4014 | * Remember position and backslash-escaping status. |
4015 | */ | ||
4016 | o_addchr(&heredoc, ch); | ||
4017 | prev = ch; | ||
4015 | jump_in: | 4018 | jump_in: |
4016 | past_EOL = heredoc.length; | 4019 | past_EOL = heredoc.length; |
4017 | do { | 4020 | /* Get 1st char of next line, possibly skipping leading tabs */ |
4018 | ch = i_getch(input); | 4021 | do { |
4019 | if (ch != EOF) | 4022 | ch = i_getch(input); |
4020 | nommu_addchr(as_string, ch); | 4023 | if (ch != EOF) |
4021 | } while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t'); | 4024 | nommu_addchr(as_string, ch); |
4025 | } while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t'); | ||
4026 | /* If this immediately ended the line, | ||
4027 | * go back to end-of-line checks. | ||
4028 | */ | ||
4029 | if (ch == '\n') | ||
4030 | goto check_heredoc_end; | ||
4031 | } | ||
4022 | } | 4032 | } |
4023 | } | 4033 | } |
4024 | if (ch == EOF) { | 4034 | if (ch == EOF) { |
diff --git a/shell/hush_test/hush-heredoc/heredoc_empty2.right b/shell/hush_test/hush-heredoc/heredoc_empty2.right new file mode 100644 index 000000000..e32c6ea58 --- /dev/null +++ b/shell/hush_test/hush-heredoc/heredoc_empty2.right | |||
@@ -0,0 +1,4 @@ | |||
1 | OK1 | ||
2 | Ok:0 | ||
3 | OK2 | ||
4 | Ok:0 | ||
diff --git a/shell/hush_test/hush-heredoc/heredoc_empty2.tests b/shell/hush_test/hush-heredoc/heredoc_empty2.tests new file mode 100755 index 000000000..20fc35fe9 --- /dev/null +++ b/shell/hush_test/hush-heredoc/heredoc_empty2.tests | |||
@@ -0,0 +1,14 @@ | |||
1 | unset a | ||
2 | |||
3 | # Heredoc with empty delimiter | ||
4 | cat <<- "" | ||
5 | OK1 | ||
6 | |||
7 | echo Ok:$? | ||
8 | |||
9 | # Heredoc with empty delimiter | ||
10 | cat <<- "" | ||
11 | OK2 | ||
12 | |||
13 | |||
14 | echo Ok:$? | ||