diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-24 14:03:18 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-24 14:03:18 +0200 |
commit | dfc739476343244371636d58561f7b743faf50d6 (patch) | |
tree | 7e41ed6fa9688c819f4d525255402179af6e0d0f | |
parent | 474cb205554919e4d017b7aeb3722d6a4ffee41d (diff) | |
download | busybox-w32-dfc739476343244371636d58561f7b743faf50d6.tar.gz busybox-w32-dfc739476343244371636d58561f7b743faf50d6.tar.bz2 busybox-w32-dfc739476343244371636d58561f7b743faf50d6.zip |
hush: handle backslash-newline in heredoc terminators
function old new delta
fetch_heredocs 479 527 +48
(ash fails this test)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 files changed, 28 insertions, 2 deletions
diff --git a/shell/ash_test/ash-heredoc/heredoc_bkslash_newline2.right b/shell/ash_test/ash-heredoc/heredoc_bkslash_newline2.right new file mode 100644 index 000000000..3d79316d7 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc_bkslash_newline2.right | |||
@@ -0,0 +1 @@ | |||
Ok1 | |||
diff --git a/shell/ash_test/ash-heredoc/heredoc_bkslash_newline2.tests b/shell/ash_test/ash-heredoc/heredoc_bkslash_newline2.tests new file mode 100755 index 000000000..1d2a26504 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc_bkslash_newline2.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | cat <<EOF | ||
2 | Ok1 | ||
3 | EO\ | ||
4 | F | ||
diff --git a/shell/hush.c b/shell/hush.c index 75bce337a..c26484b49 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -4250,6 +4250,7 @@ static char *fetch_till_str(o_string *as_string, | |||
4250 | if (ch == '\n' || ch == EOF) { | 4250 | if (ch == '\n' || ch == EOF) { |
4251 | check_heredoc_end: | 4251 | check_heredoc_end: |
4252 | if ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') { | 4252 | if ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') { |
4253 | /* End-of-line, and not a line continuation */ | ||
4253 | if (strcmp(heredoc.data + past_EOL, word) == 0) { | 4254 | if (strcmp(heredoc.data + past_EOL, word) == 0) { |
4254 | heredoc.data[past_EOL] = '\0'; | 4255 | heredoc.data[past_EOL] = '\0'; |
4255 | debug_printf_heredoc("parsed '%s' heredoc '%s'\n", word, heredoc.data); | 4256 | debug_printf_heredoc("parsed '%s' heredoc '%s'\n", word, heredoc.data); |
@@ -4275,17 +4276,32 @@ static char *fetch_till_str(o_string *as_string, | |||
4275 | if (ch == '\n') | 4276 | if (ch == '\n') |
4276 | goto check_heredoc_end; | 4277 | goto check_heredoc_end; |
4277 | } | 4278 | } |
4279 | } else { | ||
4280 | /* Backslash-line continuation in an unquoted | ||
4281 | * heredoc. This does not need special handling | ||
4282 | * for heredoc body (unquoted heredocs are | ||
4283 | * expanded on "execution" and that would take | ||
4284 | * care of this case too), but not the case | ||
4285 | * of line continuation *in terminator*: | ||
4286 | * cat <<EOF | ||
4287 | * Ok1 | ||
4288 | * EO\ | ||
4289 | * F | ||
4290 | */ | ||
4291 | heredoc.data[--heredoc.length] = '\0'; | ||
4292 | prev = 0; /* not '\' */ | ||
4293 | continue; | ||
4278 | } | 4294 | } |
4279 | } | 4295 | } |
4280 | if (ch == EOF) { | 4296 | if (ch == EOF) { |
4281 | o_free(&heredoc); | 4297 | o_free(&heredoc); |
4282 | return NULL; | 4298 | return NULL; /* error */ |
4283 | } | 4299 | } |
4284 | o_addchr(&heredoc, ch); | 4300 | o_addchr(&heredoc, ch); |
4285 | nommu_addchr(as_string, ch); | 4301 | nommu_addchr(as_string, ch); |
4286 | if (prev == '\\' && ch == '\\') | 4302 | if (prev == '\\' && ch == '\\') |
4287 | /* Correctly handle foo\\<eol> (not a line cont.) */ | 4303 | /* Correctly handle foo\\<eol> (not a line cont.) */ |
4288 | prev = 0; /* not \ */ | 4304 | prev = 0; /* not '\' */ |
4289 | else | 4305 | else |
4290 | prev = ch; | 4306 | prev = ch; |
4291 | } | 4307 | } |
diff --git a/shell/hush_test/hush-heredoc/heredoc_bkslash_newline2.right b/shell/hush_test/hush-heredoc/heredoc_bkslash_newline2.right new file mode 100644 index 000000000..3d79316d7 --- /dev/null +++ b/shell/hush_test/hush-heredoc/heredoc_bkslash_newline2.right | |||
@@ -0,0 +1 @@ | |||
Ok1 | |||
diff --git a/shell/hush_test/hush-heredoc/heredoc_bkslash_newline2.tests b/shell/hush_test/hush-heredoc/heredoc_bkslash_newline2.tests new file mode 100755 index 000000000..1d2a26504 --- /dev/null +++ b/shell/hush_test/hush-heredoc/heredoc_bkslash_newline2.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | cat <<EOF | ||
2 | Ok1 | ||
3 | EO\ | ||
4 | F | ||