klibc-bot for Herbert Xu
2019-Jan-25 03:15 UTC
[klibc] [klibc:update-dash] expand - Fix dangling left square brackets in patterns
Commit-ID: 08e03dee1485ec4823b3afd465b32938b3a40045 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=08e03dee1485ec4823b3afd465b32938b3a40045 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Sat, 3 Sep 2016 21:58:50 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Fri, 25 Jan 2019 02:57:21 +0000 [klibc] expand - Fix dangling left square brackets in patterns When there is an unmatched left square bracket in patterns, pmatch will behave strangely and exhibit undefined behaviour. This patch (based on Harld van Dijk's original) fixes this by treating it as a literal left square bracket. Reported-by: Olof Johansson <olof at ethup.se> Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/expand.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr/dash/expand.c b/usr/dash/expand.c index 9079b74b..e2d563fe 100644 --- a/usr/dash/expand.c +++ b/usr/dash/expand.c @@ -1584,14 +1584,14 @@ pmatch(const char *pattern, const char *string) p++; } found = 0; - chr = *q++; + chr = *q; if (chr == '\0') return 0; c = *p++; do { if (!c) { p = startp; - c = *p; + c = '['; goto dft; } if (c == '[') { @@ -1618,6 +1618,7 @@ pmatch(const char *pattern, const char *string) } while ((c = *p++) != ']'); if (found == invert) return 0; + q++; break; } dft: default: