From a4d35dc3fde82457d1998c89aec8127914913b61 Mon Sep 17 00:00:00 2001 From: Igor Burago Date: Wed, 12 Oct 2022 02:39:43 +0800 Subject: [PATCH] plumber: use strtoul to parse subexpression match variable substitutions --- src/cmd/plumb/rules.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/cmd/plumb/rules.c b/src/cmd/plumb/rules.c index 4bd02e44..b899231f 100644 --- a/src/cmd/plumb/rules.c +++ b/src/cmd/plumb/rules.c @@ -254,36 +254,21 @@ filename(Exec *e, char *name) return cleanname(buf); } -static char* -subexpmatch(Exec *e, char *s, int *numlen) -{ - int n, d, ok; - char *t; - - n = 0; - ok = 1; - for(t = s; '0'<=*t && *t<='9'; t++) - if(ok){ - d = *t-'0'; - if(dmatch[n]; -} - char* dollar(Exec *e, char *s, int *namelen) { int n; + ulong m; + char *t; static char *abuf; - if(e!=nil && '0'<=s[0] && s[0]<='9') - return nonnil(subexpmatch(e, s, namelen)); + if(e!=nil && '0'<=s[0] && s[0]<='9'){ + m = strtoul(s, &t, 10); + *namelen = t-s; + if(t==s || m>=NMATCHSUBEXP) + return ""; + return nonnil(e->match[m]); + } n = scanvarname(s)-s; *namelen = n;