Re: Regression in dash 0.5.10 related to string parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Leah Neukirchen <leah@xxxxxxxx> wrote:
> Hi,
> 
> Commit ab1cecb40, first released in 0.5.10, introduces a parsing bug
> related to backslashes in singly-quoted strings:
> 
> echo 'foo\
> bar'
> 
> According to POSIX, this has to output
> 
> foo\
> bar
> 
> However, in dash 0.5.10, it outputs "foobar".
> 
> Found by users of the Void Linux project:
> https://github.com/voidlinux/void-packages/issues/14282

Thanks for the report.  This patch should fix the problem:

---8<---
Subject: parser: Fix incorrect eating of backslash newlines

With the introduction of synstack->syntax, a number of references
to the syntax variable was missed during the conversion.  This
causes backslash newlines to be incorrectly removed in single
quote context.

This patch also combines these calls into a new helper function
pgetc_top.

Fixes: ab1cecb40478 ("parser: Add syntax stack for recursive...")
Reported-by: Leah Neukirchen <leah@xxxxxxxx>
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

diff --git a/src/parser.c b/src/parser.c
index 8e40781..8bd3db4 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -853,6 +853,11 @@ static int pgetc_eatbnl(void)
 	return c;
 }
 
+static int pgetc_top(struct synstack *stack)
+{
+	return stack->syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl();
+}
+
 static void synstack_push(struct synstack **stack, struct synstack *next,
 			  const char *syntax)
 {
@@ -915,7 +920,7 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
 			attyline();
 			if (synstack->syntax == BASESYNTAX)
 				return readtoken();
-			c = syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl();
+			c = pgetc_top(synstack);
 			goto loop;
 		}
 #endif
@@ -929,7 +934,7 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
 					goto endword;	/* exit outer loop */
 				USTPUTC(c, out);
 				nlprompt();
-				c = syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl();
+				c = pgetc_top(synstack);
 				goto loop;		/* continue outer loop */
 			case CWORD:
 				USTPUTC(c, out);
@@ -1056,7 +1061,7 @@ toggledq:
 					USTPUTC(c, out);
 				}
 			}
-			c = syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl();
+			c = pgetc_top(synstack);
 		}
 	}
 endword:
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux