aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2011-03-15 17:41:53 +0800
committermaximilian attems <max@stro.at>2011-06-03 18:44:14 +0200
commite651cea64590e7921da698cd909723ad658c7167 (patch)
tree402dd7f6d68b722837046323d693faf47924e0b6
parent7a244f7d2c1f405729a647f205314f3b14f4468f (diff)
downloadklibc-e651cea64590e7921da698cd909723ad658c7167.tar.gz
[klibc] [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 <<EOF && > $(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 <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/dash/parser.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr/dash/parser.c b/usr/dash/parser.c
index 0bfd6203e901a..528d0052da80b 100644
--- a/usr/dash/parser.c
+++ b/usr/dash/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))) {