[git commit] hush: fix recent breakage from parse_stream() changes

Denys Vlasenko vda.linux at googlemail.com
Wed Apr 11 18:00:43 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=f693b606b732437bb1265c2ec883d93127f3f38e
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
parse_stream                                        3808    3821     +13

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash_test/ash-parsing/bkslash_newline3.right  |  1 +
 shell/ash_test/ash-parsing/bkslash_newline3.tests  |  4 ++
 shell/hush.c                                       | 44 +++++++++++-----------
 .../hush_test/hush-parsing/bkslash_newline3.right  |  1 +
 .../hush_test/hush-parsing/bkslash_newline3.tests  |  4 ++
 5 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/shell/ash_test/ash-parsing/bkslash_newline3.right b/shell/ash_test/ash-parsing/bkslash_newline3.right
new file mode 100644
index 000000000..e635074e5
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_newline3.right
@@ -0,0 +1 @@
+a:[a]
diff --git a/shell/ash_test/ash-parsing/bkslash_newline3.tests b/shell/ash_test/ash-parsing/bkslash_newline3.tests
new file mode 100755
index 000000000..2accd4395
--- /dev/null
+++ b/shell/ash_test/ash-parsing/bkslash_newline3.tests
@@ -0,0 +1,4 @@
+for s in 	\
+a; do
+	echo "a:[$s]"
+done
diff --git a/shell/hush.c b/shell/hush.c
index 8e95a26a6..c77700175 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -5075,7 +5075,6 @@ static struct pipe *parse_stream(char **pstring,
 			debug_printf_parse("parse_stream return %p\n", pi);
 			return pi;
 		}
-		nommu_addchr(&ctx.as_string, ch);
 
 		/* Handle "'" and "\" first, as they won't play nice with
 		 * i_peek_and_eat_bkslash_nl() anyway:
@@ -5085,6 +5084,28 @@ static struct pipe *parse_stream(char **pstring,
 		 *   '
 		 * would break.
 		 */
+		if (ch == '\\') {
+			ch = i_getch(input);
+			if (ch == '\n')
+				continue; /* drop \<newline>, get next char */
+			nommu_addchr(&ctx.as_string, '\\');
+			o_addchr(&ctx.word, '\\');
+			if (ch == EOF) {
+				/* Testcase: eval 'echo Ok\' */
+				/* bash-4.3.43 was removing backslash,
+				 * but 4.4.19 retains it, most other shells too
+				 */
+				continue; /* get next char */
+			}
+			/* Example: echo Hello \2>file
+			 * we need to know that word 2 is quoted
+			 */
+			ctx.word.has_quoted_part = 1;
+			nommu_addchr(&ctx.as_string, ch);
+			o_addchr(&ctx.word, ch);
+			continue; /* get next char */
+		}
+		nommu_addchr(&ctx.as_string, ch);
 		if (ch == '\'') {
 			ctx.word.has_quoted_part = 1;
 			next = i_getch(input);
@@ -5110,27 +5131,6 @@ static struct pipe *parse_stream(char **pstring,
 			}
 			continue; /* get next char */
 		}
-		if (ch == '\\') {
-			/*nommu_addchr(&ctx.as_string, '\\'); - already done */
-			o_addchr(&ctx.word, '\\');
-			ch = i_getch(input);
-			if (ch == EOF) {
-				/* Testcase: eval 'echo Ok\' */
-
-#if 0 /* bash-4.3.43 was removing backslash, but 4.4.19 retains it, most other shells too */
-				/* Remove trailing '\' from ctx.as_string */
-				ctx.as_string.data[--ctx.as_string.length] = '\0';
-#endif
-				continue; /* get next char */
-			}
-			/* Example: echo Hello \2>file
-			 * we need to know that word 2 is quoted
-			 */
-			ctx.word.has_quoted_part = 1;
-			nommu_addchr(&ctx.as_string, ch);
-			o_addchr(&ctx.word, ch);
-			continue; /* get next char */
-		}
 
 		next = '\0';
 		if (ch != '\n')
diff --git a/shell/hush_test/hush-parsing/bkslash_newline3.right b/shell/hush_test/hush-parsing/bkslash_newline3.right
new file mode 100644
index 000000000..e635074e5
--- /dev/null
+++ b/shell/hush_test/hush-parsing/bkslash_newline3.right
@@ -0,0 +1 @@
+a:[a]
diff --git a/shell/hush_test/hush-parsing/bkslash_newline3.tests b/shell/hush_test/hush-parsing/bkslash_newline3.tests
new file mode 100755
index 000000000..2accd4395
--- /dev/null
+++ b/shell/hush_test/hush-parsing/bkslash_newline3.tests
@@ -0,0 +1,4 @@
+for s in 	\
+a; do
+	echo "a:[$s]"
+done


More information about the busybox-cvs mailing list