From ec2c84d3c4dba4b74440d72bdd1de416a9acd2a9 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Tue, 15 Mar 2011 17:41:53 +0800 Subject: [PARSER] Fix clobbering of checkkwd On Sun, Nov 07, 2010 at 02:21:21AM +0000, Jonathan Nieder wrote: > > Just ran into some strange behavior: > > $ cat test.sh > #!/bin/sh > echo hello >greeting > cat < $(cat greeting) > EOF > { > echo $? > cat greeting > } >/dev/null > > > $ sh test.sh > hello > test.sh: 7: {: not found > 127 > hello > test.sh: 10: Syntax error: "}" unexpected > > bash, mksh, pdksh, and ksh93 all print hello as expected. The problem > is reproducible with all versions of dash in the git repo. This is caused by the clobbering of checkkwd due to readtoken recursion while parsing a here document. This patch fixes it by saving the original value of checkkwd. Reported-by: Jonathan Nieder Signed-off-by: Herbert Xu --- src/parser.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 0bfd620..528d005 100644 --- a/src/parser.c +++ b/src/parser.c @@ -687,6 +687,7 @@ STATIC int readtoken(void) { int t; + int kwd = checkkwd; #ifdef DEBUG int alreadyseen = tokpushback; #endif @@ -697,7 +698,7 @@ top: /* * eat newlines */ - if (checkkwd & CHKNL) { + if (kwd & CHKNL) { while (t == TNL) { parseheredoc(); t = xxreadtoken(); @@ -711,7 +712,7 @@ top: /* * check for keywords */ - if (checkkwd & CHKKWD) { + if (kwd & CHKKWD) { const char *const *pp; if ((pp = findkwd(wordtext))) { -- cgit 1.4.1