diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-06 11:46:03 +0200 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-06 11:46:03 +0200 |
| commit | c3adfacd229dd94b1ee4800fb364d514eef4aca5 (patch) | |
| tree | 1245cc6f1915bfe6af65fd152962fff889fda78d /shell | |
| parent | 77b32ccbf2a1a77911b486b673008a4cb82bb8b7 (diff) | |
| download | busybox-w32-c3adfacd229dd94b1ee4800fb364d514eef4aca5.tar.gz busybox-w32-c3adfacd229dd94b1ee4800fb364d514eef4aca5.tar.bz2 busybox-w32-c3adfacd229dd94b1ee4800fb364d514eef4aca5.zip | |
hush: fix another corner case with backslashes in heredocs
function old new delta
parse_stream 2395 2432 +37
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 10 | ||||
| -rw-r--r-- | shell/hush_test/hush-misc/heredoc_backslash1.right | 8 | ||||
| -rwxr-xr-x | shell/hush_test/hush-misc/heredoc_backslash1.tests | 8 |
3 files changed, 24 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c index e8aef2d7e..4e29f01a1 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -3174,6 +3174,7 @@ static char *fetch_till_str(o_string *as_string, | |||
| 3174 | ch = i_getch(input); | 3174 | ch = i_getch(input); |
| 3175 | nommu_addchr(as_string, ch); | 3175 | nommu_addchr(as_string, ch); |
| 3176 | if (ch == '\n' | 3176 | if (ch == '\n' |
| 3177 | /* TODO: or EOF? (heredoc delimiter may end with <eof>, not only <eol> */ | ||
| 3177 | && ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') | 3178 | && ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') |
| 3178 | ) { | 3179 | ) { |
| 3179 | if (strcmp(heredoc.data + past_EOL, word) == 0) { | 3180 | if (strcmp(heredoc.data + past_EOL, word) == 0) { |
| @@ -3182,7 +3183,8 @@ static char *fetch_till_str(o_string *as_string, | |||
| 3182 | return heredoc.data; | 3183 | return heredoc.data; |
| 3183 | } | 3184 | } |
| 3184 | do { | 3185 | do { |
| 3185 | o_addchr(&heredoc, ch); | 3186 | o_addchr(&heredoc, '\n'); |
| 3187 | prev = 0; /* not \ */ | ||
| 3186 | past_EOL = heredoc.length; | 3188 | past_EOL = heredoc.length; |
| 3187 | jump_in: | 3189 | jump_in: |
| 3188 | do { | 3190 | do { |
| @@ -3196,8 +3198,12 @@ static char *fetch_till_str(o_string *as_string, | |||
| 3196 | return NULL; | 3198 | return NULL; |
| 3197 | } | 3199 | } |
| 3198 | o_addchr(&heredoc, ch); | 3200 | o_addchr(&heredoc, ch); |
| 3201 | if (prev == '\\' && ch == '\\') | ||
| 3202 | /* Correctly handle foo\\<eol> (not a line cont.) */ | ||
| 3203 | prev = 0; /* not \ */ | ||
| 3204 | else | ||
| 3205 | prev = ch; | ||
| 3199 | nommu_addchr(as_string, ch); | 3206 | nommu_addchr(as_string, ch); |
| 3200 | prev = ch; | ||
| 3201 | } | 3207 | } |
| 3202 | } | 3208 | } |
| 3203 | 3209 | ||
diff --git a/shell/hush_test/hush-misc/heredoc_backslash1.right b/shell/hush_test/hush-misc/heredoc_backslash1.right index 234c0172f..2633908fb 100644 --- a/shell/hush_test/hush-misc/heredoc_backslash1.right +++ b/shell/hush_test/hush-misc/heredoc_backslash1.right | |||
| @@ -1,12 +1,16 @@ | |||
| 1 | Quoted heredoc: | 1 | Quoted heredoc: |
| 2 | a\ | 2 | a\ |
| 3 | b | 3 | b |
| 4 | a\\ | ||
| 5 | b | ||
| 4 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 6 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 5 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 7 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 6 | c\ | 8 | c\ |
| 7 | 9 | ||
| 8 | Unquoted heredoc: | 10 | Unquoted heredoc: |
| 9 | a b | 11 | a b |
| 12 | a\ | ||
| 13 | b | ||
| 10 | 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- | 14 | 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- |
| 11 | -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- | 15 | -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- |
| 12 | cEOF2 | 16 | cEOF2 |
| @@ -14,12 +18,16 @@ cEOF2 | |||
| 14 | Quoted -heredoc: | 18 | Quoted -heredoc: |
| 15 | a\ | 19 | a\ |
| 16 | b | 20 | b |
| 21 | a\\ | ||
| 22 | b | ||
| 17 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 23 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 18 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 24 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 19 | c\ | 25 | c\ |
| 20 | 26 | ||
| 21 | Unquoted -heredoc: | 27 | Unquoted -heredoc: |
| 22 | a b | 28 | a b |
| 29 | a\ | ||
| 30 | b | ||
| 23 | 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- | 31 | 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- |
| 24 | -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- | 32 | -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- |
| 25 | cEOF4 | 33 | cEOF4 |
diff --git a/shell/hush_test/hush-misc/heredoc_backslash1.tests b/shell/hush_test/hush-misc/heredoc_backslash1.tests index b70467df8..22045d42e 100755 --- a/shell/hush_test/hush-misc/heredoc_backslash1.tests +++ b/shell/hush_test/hush-misc/heredoc_backslash1.tests | |||
| @@ -7,6 +7,8 @@ echo Quoted heredoc: | |||
| 7 | cat <<"EOF1" | 7 | cat <<"EOF1" |
| 8 | a\ | 8 | a\ |
| 9 | b | 9 | b |
| 10 | a\\ | ||
| 11 | b | ||
| 10 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 12 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 11 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 13 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 12 | c\ | 14 | c\ |
| @@ -17,6 +19,8 @@ echo Unquoted heredoc: | |||
| 17 | cat <<EOF2 | 19 | cat <<EOF2 |
| 18 | a\ | 20 | a\ |
| 19 | b | 21 | b |
| 22 | a\\ | ||
| 23 | b | ||
| 20 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 24 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 21 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 25 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 22 | c\ | 26 | c\ |
| @@ -28,6 +32,8 @@ echo Quoted -heredoc: | |||
| 28 | cat <<-"EOF3" | 32 | cat <<-"EOF3" |
| 29 | a\ | 33 | a\ |
| 30 | b | 34 | b |
| 35 | a\\ | ||
| 36 | b | ||
| 31 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 37 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 32 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 38 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 33 | c\ | 39 | c\ |
| @@ -39,6 +45,8 @@ echo Unquoted -heredoc: | |||
| 39 | cat <<-EOF4 | 45 | cat <<-EOF4 |
| 40 | a\ | 46 | a\ |
| 41 | b | 47 | b |
| 48 | a\\ | ||
| 49 | b | ||
| 42 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 50 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 43 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- | 51 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 44 | c\ | 52 | c\ |
