From ad092191a3f281c2d14089c86757305403a9de64 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Sat, 3 Sep 2016 21:58:50 +0800 Subject: 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 Signed-off-by: Herbert Xu --- src/expand.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/expand.c b/src/expand.c index 36bea76..2a50830 100644 --- a/src/expand.c +++ b/src/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: -- cgit 1.4.1