[git commit] ash: parser: Fix parsing of ${}

Denys Vlasenko vda.linux at googlemail.com
Sun Aug 5 16:11:15 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=58eb805c2c453c6764acbd65f5604465438d9272
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Upstream commit:

    Date: Tue, 3 Apr 2018 00:40:25 +0800
    parser: Fix parsing of ${}

    dash -c 'echo ${}' should print "Bad subtitution" but instead
    fails with "Syntax error: Missing '}'".  This is caused by us
    reading an extra character beyond the right brace.  This patch
    fixes it so that this construct only fails during expansion rather
    than during parsing.

    Fixes: 3df3edd13389 ("[PARSER] Report substition errors at...")
    Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>

function                                             old     new   delta
readtoken1                                          2907    2916      +9

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index f74bef6b1..b596833e7 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12431,7 +12431,7 @@ parsesub: {
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
 			} while (isdigit(c));
-		} else {
+		} else if (c != '}') {
 			/* $[{[#]]<specialchar>[}] */
 			int cc = c;
 
@@ -12457,7 +12457,8 @@ parsesub: {
 			}
 
 			USTPUTC(cc, out);
-		}
+		} else
+			goto badsub;
 
 		if (c != '}' && subtype == VSLENGTH) {
 			/* ${#VAR didn't end with } */


More information about the busybox-cvs mailing list