aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-01 03:04:55 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-01 03:04:55 +0200
commit1e5111b0f80b1f3d7f2fc8254cb70de067317403 (patch)
treeee7a49ce2dad513159b7c62e43d7a645950bf207
parent32e183e63ecb46595a480ab66120795ed9c9e0df (diff)
downloadbusybox-w32-1e5111b0f80b1f3d7f2fc8254cb70de067317403.tar.gz
busybox-w32-1e5111b0f80b1f3d7f2fc8254cb70de067317403.tar.bz2
busybox-w32-1e5111b0f80b1f3d7f2fc8254cb70de067317403.zip
ash,hush: handle a few more bkslash-newline cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c2
-rw-r--r--shell/ash_test/ash-parsing/bkslash_newline1.right4
-rwxr-xr-xshell/ash_test/ash-parsing/bkslash_newline1.tests8
-rw-r--r--shell/ash_test/ash-parsing/bkslash_newline2.right4
-rwxr-xr-xshell/ash_test/ash-parsing/bkslash_newline2.tests4
-rw-r--r--shell/hush.c14
-rw-r--r--shell/hush_test/hush-parsing/bkslash_newline1.right4
-rwxr-xr-xshell/hush_test/hush-parsing/bkslash_newline1.tests8
-rw-r--r--shell/hush_test/hush-parsing/bkslash_newline2.right4
-rwxr-xr-xshell/hush_test/hush-parsing/bkslash_newline2.tests4
10 files changed, 53 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c
index a7767b4f8..454bc3317 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12649,7 +12649,7 @@ xxreadtoken(void)
12649 break; /* return readtoken1(...) */ 12649 break; /* return readtoken1(...) */
12650 12650
12651 if ((int)(p - xxreadtoken_chars) >= xxreadtoken_singles) { 12651 if ((int)(p - xxreadtoken_chars) >= xxreadtoken_singles) {
12652 int cc = pgetc(); 12652 int cc = pgetc_eatbnl();
12653 if (cc == c) { /* double occurrence? */ 12653 if (cc == c) { /* double occurrence? */
12654 p += xxreadtoken_doubles + 1; 12654 p += xxreadtoken_doubles + 1;
12655 } else { 12655 } else {
diff --git a/shell/ash_test/ash-parsing/bkslash_newline1.right b/shell/ash_test/ash-parsing/bkslash_newline1.right
new file mode 100644
index 000000000..97ea0c197
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_newline1.right
@@ -0,0 +1,4 @@
1and1
2and2
3or1
4ok
diff --git a/shell/ash_test/ash-parsing/bkslash_newline1.tests b/shell/ash_test/ash-parsing/bkslash_newline1.tests
new file mode 100755
index 000000000..6e374c4fb
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_newline1.tests
@@ -0,0 +1,8 @@
1echo and1 &\
2& echo and2
3
4echo or1 |\
5| echo NOT SHOWN
6
7case w in a) echo SKIP;\
8; w) echo ok;; esac;
diff --git a/shell/ash_test/ash-parsing/bkslash_newline2.right b/shell/ash_test/ash-parsing/bkslash_newline2.right
new file mode 100644
index 000000000..c863c5453
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_newline2.right
@@ -0,0 +1,4 @@
1Line with one backslash:
2\
3
4Ok:0
diff --git a/shell/ash_test/ash-parsing/bkslash_newline2.tests b/shell/ash_test/ash-parsing/bkslash_newline2.tests
new file mode 100755
index 000000000..47d63042d
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_newline2.tests
@@ -0,0 +1,4 @@
1echo Line with one backslash:
2echo '\
3'
4echo Ok:$?
diff --git a/shell/hush.c b/shell/hush.c
index 533d45ac3..4b8641d19 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -4980,8 +4980,14 @@ static struct pipe *parse_stream(char **pstring,
4980 nommu_addchr(&ctx.as_string, ch); 4980 nommu_addchr(&ctx.as_string, ch);
4981 4981
4982 next = '\0'; 4982 next = '\0';
4983 if (ch != '\n') 4983 if (ch != '\n') {
4984 next = i_peek(input); 4984 next = i_peek(input);
4985 /* Can't use i_peek_and_eat_bkslash_nl(input) here:
4986 * echo '\
4987 * '
4988 * will break.
4989 */
4990 }
4985 4991
4986 is_special = "{}<>;&|()#'" /* special outside of "str" */ 4992 is_special = "{}<>;&|()#'" /* special outside of "str" */
4987 "\\$\"" IF_HUSH_TICK("`") /* always special */ 4993 "\\$\"" IF_HUSH_TICK("`") /* always special */
@@ -5375,7 +5381,7 @@ static struct pipe *parse_stream(char **pstring,
5375 /* Eat multiple semicolons, detect 5381 /* Eat multiple semicolons, detect
5376 * whether it means something special */ 5382 * whether it means something special */
5377 while (1) { 5383 while (1) {
5378 ch = i_peek(input); 5384 ch = i_peek_and_eat_bkslash_nl(input);
5379 if (ch != ';') 5385 if (ch != ';')
5380 break; 5386 break;
5381 ch = i_getch(input); 5387 ch = i_getch(input);
@@ -5397,6 +5403,8 @@ static struct pipe *parse_stream(char **pstring,
5397 if (done_word(&dest, &ctx)) { 5403 if (done_word(&dest, &ctx)) {
5398 goto parse_error; 5404 goto parse_error;
5399 } 5405 }
5406 if (next == '\\')
5407 next = i_peek_and_eat_bkslash_nl(input);
5400 if (next == '&') { 5408 if (next == '&') {
5401 ch = i_getch(input); 5409 ch = i_getch(input);
5402 nommu_addchr(&ctx.as_string, ch); 5410 nommu_addchr(&ctx.as_string, ch);
@@ -5413,6 +5421,8 @@ static struct pipe *parse_stream(char **pstring,
5413 if (ctx.ctx_res_w == RES_MATCH) 5421 if (ctx.ctx_res_w == RES_MATCH)
5414 break; /* we are in case's "word | word)" */ 5422 break; /* we are in case's "word | word)" */
5415#endif 5423#endif
5424 if (next == '\\')
5425 next = i_peek_and_eat_bkslash_nl(input);
5416 if (next == '|') { /* || */ 5426 if (next == '|') { /* || */
5417 ch = i_getch(input); 5427 ch = i_getch(input);
5418 nommu_addchr(&ctx.as_string, ch); 5428 nommu_addchr(&ctx.as_string, ch);
diff --git a/shell/hush_test/hush-parsing/bkslash_newline1.right b/shell/hush_test/hush-parsing/bkslash_newline1.right
new file mode 100644
index 000000000..97ea0c197
--- /dev/null
+++ b/shell/hush_test/hush-parsing/bkslash_newline1.right
@@ -0,0 +1,4 @@
1and1
2and2
3or1
4ok
diff --git a/shell/hush_test/hush-parsing/bkslash_newline1.tests b/shell/hush_test/hush-parsing/bkslash_newline1.tests
new file mode 100755
index 000000000..6e374c4fb
--- /dev/null
+++ b/shell/hush_test/hush-parsing/bkslash_newline1.tests
@@ -0,0 +1,8 @@
1echo and1 &\
2& echo and2
3
4echo or1 |\
5| echo NOT SHOWN
6
7case w in a) echo SKIP;\
8; w) echo ok;; esac;
diff --git a/shell/hush_test/hush-parsing/bkslash_newline2.right b/shell/hush_test/hush-parsing/bkslash_newline2.right
new file mode 100644
index 000000000..c863c5453
--- /dev/null
+++ b/shell/hush_test/hush-parsing/bkslash_newline2.right
@@ -0,0 +1,4 @@
1Line with one backslash:
2\
3
4Ok:0
diff --git a/shell/hush_test/hush-parsing/bkslash_newline2.tests b/shell/hush_test/hush-parsing/bkslash_newline2.tests
new file mode 100755
index 000000000..47d63042d
--- /dev/null
+++ b/shell/hush_test/hush-parsing/bkslash_newline2.tests
@@ -0,0 +1,4 @@
1echo Line with one backslash:
2echo '\
3'
4echo Ok:$?