[git commit] ash: [PARSER] Catch variable length expansions on non-existant specials

Denys Vlasenko vda.linux at googlemail.com
Mon Aug 14 12:23:45 UTC 2017


commit: https://git.busybox.net/busybox/commit/?id=452cc1d9bdd7848e960919916de7c405512cad05
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Upstream commit:

    Date: Thu, 30 Oct 2014 11:53:35 +0800
    [PARSER] Catch variable length expansions on non-existant specials

    Currently we only check special variable names that follow directly
    after $ or ${.  So errors such as ${#&} are not caught.  This patch
    fixes that by moving the is_special check to just before we print out
    the special variable name.

    Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>

function                                             old     new   delta
readtoken1                                          2630    2635      +5

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

diff --git a/shell/ash.c b/shell/ash.c
index 15c7c32..1917b55 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12119,7 +12119,7 @@ parsesub: {
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
 			} while (isdigit(c));
-		} else if (is_special(c)) {
+		} else {
 			/* $[{[#]]<specialchar>[}] */
 			int cc = c;
 
@@ -12137,10 +12137,16 @@ parsesub: {
 					cc = '#';
 				}
 			}
+
+			if (!is_special(cc)) {
+				if (subtype == VSLENGTH)
+					subtype = 0;
+				goto badsub;
+			}
+
 			USTPUTC(cc, out);
-		} else {
-			goto badsub;
 		}
+
 		if (c != '}' && subtype == VSLENGTH) {
 			/* ${#VAR didn't end with } */
 			goto badsub;


More information about the busybox-cvs mailing list