parser: Fix backquote support in here-document EOF mark
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 1 Apr 2018 14:38:32 +0000 (16:38 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 1 Apr 2018 14:38:32 +0000 (16:38 +0200)
Upstream commit:

    Author: Herbert Xu <herbert@gondor.apana.org.au>
    Date:   Thu Mar 15 18:27:30 2018 +0800
    parser: Fix backquote support in here-document EOF mark

    Currently using backquotes in a here-document EOF mark is broken
    because dash tries to do command substitution on it.  This patch
    fixes it by checking whether we're looking for an EOF mark during
    tokenisation.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
With added fix for quoted-ness of the EOF mark.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-heredoc/heredoc_backquote1.right [new file with mode: 0644]
shell/ash_test/ash-heredoc/heredoc_backquote1.tests [new file with mode: 0755]
shell/hush_test/hush-heredoc/heredoc_backquote1.right [new file with mode: 0644]
shell/hush_test/hush-heredoc/heredoc_backquote1.tests [new file with mode: 0755]

index 454bc3317415731c5692fa09d992d37b815eb91b..cf1d062fb8d741453ba210140be71618687c912f 100644 (file)
@@ -12093,6 +12093,12 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
                        break;
 #endif
                case CBQUOTE:   /* '`' */
+                       if (checkkwd & CHKEOFMARK) {
+                               quotef = 1;
+                               USTPUTC('`', out);
+                               break;
+                       }
+
                        PARSEBACKQOLD();
                        break;
                case CENDFILE:
diff --git a/shell/ash_test/ash-heredoc/heredoc_backquote1.right b/shell/ash_test/ash-heredoc/heredoc_backquote1.right
new file mode 100644 (file)
index 0000000..0be2a32
--- /dev/null
@@ -0,0 +1,5 @@
+heredoc1
+Ok1:0
+heredoc2
+EO`false`F
+Ok2:0
diff --git a/shell/ash_test/ash-heredoc/heredoc_backquote1.tests b/shell/ash_test/ash-heredoc/heredoc_backquote1.tests
new file mode 100755 (executable)
index 0000000..ec3d8fe
--- /dev/null
@@ -0,0 +1,10 @@
+cat <<EO`true`F
+heredoc1
+EO`true`F
+echo Ok1:$?
+
+cat <<EO`true`F
+heredoc2
+EO`false`F
+EO`true`F
+echo Ok2:$?
diff --git a/shell/hush_test/hush-heredoc/heredoc_backquote1.right b/shell/hush_test/hush-heredoc/heredoc_backquote1.right
new file mode 100644 (file)
index 0000000..0be2a32
--- /dev/null
@@ -0,0 +1,5 @@
+heredoc1
+Ok1:0
+heredoc2
+EO`false`F
+Ok2:0
diff --git a/shell/hush_test/hush-heredoc/heredoc_backquote1.tests b/shell/hush_test/hush-heredoc/heredoc_backquote1.tests
new file mode 100755 (executable)
index 0000000..ec3d8fe
--- /dev/null
@@ -0,0 +1,10 @@
+cat <<EO`true`F
+heredoc1
+EO`true`F
+echo Ok1:$?
+
+cat <<EO`true`F
+heredoc2
+EO`false`F
+EO`true`F
+echo Ok2:$?