[git commit] hush: fix handling of heredocs starting with empty lines

Denys Vlasenko vda.linux at googlemail.com
Mon Jul 23 13:43:57 UTC 2018


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

function                                             old     new   delta
parse_stream                                        2748    2759     +11

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash_test/ash-heredoc/heredoc_empty3.right   | 2 ++
 shell/ash_test/ash-heredoc/heredoc_empty3.tests   | 4 ++++
 shell/hush.c                                      | 8 ++++++++
 shell/hush_test/hush-heredoc/heredoc_empty3.right | 2 ++
 shell/hush_test/hush-heredoc/heredoc_empty3.tests | 4 ++++
 5 files changed, 20 insertions(+)

diff --git a/shell/ash_test/ash-heredoc/heredoc_empty3.right b/shell/ash_test/ash-heredoc/heredoc_empty3.right
new file mode 100644
index 000000000..0b54a9c93
--- /dev/null
+++ b/shell/ash_test/ash-heredoc/heredoc_empty3.right
@@ -0,0 +1,2 @@
+
+Ok
diff --git a/shell/ash_test/ash-heredoc/heredoc_empty3.tests b/shell/ash_test/ash-heredoc/heredoc_empty3.tests
new file mode 100755
index 000000000..828c2dd89
--- /dev/null
+++ b/shell/ash_test/ash-heredoc/heredoc_empty3.tests
@@ -0,0 +1,4 @@
+cat <<EOF
+
+Ok
+EOF
diff --git a/shell/hush.c b/shell/hush.c
index 4fdd15900..89e06df4d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -4226,6 +4226,14 @@ static char *fetch_till_str(o_string *as_string,
 	int prev = 0; /* not \ */
 	int ch;
 
+	/* Starting with "" is necessary for this case:
+	 * cat <<EOF
+	 *
+	 * xxx
+	 * EOF
+	 */
+	heredoc.data = xzalloc(1); /* start as "", not as NULL */
+
 	goto jump_in;
 
 	while (1) {
diff --git a/shell/hush_test/hush-heredoc/heredoc_empty3.right b/shell/hush_test/hush-heredoc/heredoc_empty3.right
new file mode 100644
index 000000000..0b54a9c93
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_empty3.right
@@ -0,0 +1,2 @@
+
+Ok
diff --git a/shell/hush_test/hush-heredoc/heredoc_empty3.tests b/shell/hush_test/hush-heredoc/heredoc_empty3.tests
new file mode 100755
index 000000000..828c2dd89
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_empty3.tests
@@ -0,0 +1,4 @@
+cat <<EOF
+
+Ok
+EOF


More information about the busybox-cvs mailing list