[klibc] [klibc:update-dash] parser: Fix parsing of ${}

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Thu Jan 24 19:16:00 PST 2019


Commit-ID:  5e8e1a2d765473c0fe0321576e498fe114b76026
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=5e8e1a2d765473c0fe0321576e498fe114b76026
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Tue, 3 Apr 2018 00:40:25 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Fri, 25 Jan 2019 02:57:21 +0000

[klibc] 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>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/parser.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/usr/dash/parser.c b/usr/dash/parser.c
index 6a8a4a43..efa8060f 100644
--- a/usr/dash/parser.c
+++ b/usr/dash/parser.c
@@ -1262,7 +1262,7 @@ varname:
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
 			} while (is_digit(c));
-		} else {
+		} else if (c != '}') {
 			int cc = c;
 
 			c = pgetc_eatbnl();
@@ -1290,7 +1290,8 @@ varname:
 			}
 
 			USTPUTC(cc, out);
-		}
+		} else
+			goto badsub;
 
 		if (subtype == 0) {
 			int cc = c;


More information about the klibc mailing list