ash: fix error during recursive processing of here document
authorRon Yorston <rmy@pobox.com>
Thu, 29 Oct 2015 16:44:56 +0000 (16:44 +0000)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 29 Oct 2015 19:45:36 +0000 (20:45 +0100)
Save the value of the checkkwd flag to prevent it being clobbered
during recursion.

Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken                                            190     203     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-heredoc/heredoc3.right [new file with mode: 0644]
shell/ash_test/ash-heredoc/heredoc3.tests [new file with mode: 0755]

index 0d7cac0b59bdc21e7b0a7f5abf7a0349d47b3f19..384c7b9e47c716e3f2a00fdcb4ff52e1c508ca9e 100644 (file)
@@ -11899,6 +11899,7 @@ static int
 readtoken(void)
 {
        int t;
+       int kwd = checkkwd;
 #if DEBUG
        smallint alreadyseen = tokpushback;
 #endif
@@ -11912,7 +11913,7 @@ readtoken(void)
        /*
         * eat newlines
         */
-       if (checkkwd & CHKNL) {
+       if (kwd & CHKNL) {
                while (t == TNL) {
                        parseheredoc();
                        t = xxreadtoken();
@@ -11926,7 +11927,7 @@ readtoken(void)
        /*
         * check for keywords
         */
-       if (checkkwd & CHKKWD) {
+       if (kwd & CHKKWD) {
                const char *const *pp;
 
                pp = findkwd(wordtext);
diff --git a/shell/ash_test/ash-heredoc/heredoc3.right b/shell/ash_test/ash-heredoc/heredoc3.right
new file mode 100644 (file)
index 0000000..ce01362
--- /dev/null
@@ -0,0 +1 @@
+hello
diff --git a/shell/ash_test/ash-heredoc/heredoc3.tests b/shell/ash_test/ash-heredoc/heredoc3.tests
new file mode 100755 (executable)
index 0000000..96c227c
--- /dev/null
@@ -0,0 +1,9 @@
+echo hello >greeting
+cat <<EOF &&
+$(cat greeting)
+EOF
+{
+       echo $?
+       cat greeting
+} >/dev/null
+rm greeting