[klibc] [klibc:update-dash] dash: expand - Fix dangling left square brackets in patterns

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Sat Mar 28 14:48:52 PDT 2020


Commit-ID:  9885e7650e5daf90ddc2a9bb1dfc6af14e86ad9d
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=9885e7650e5daf90ddc2a9bb1dfc6af14e86ad9d
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: Sat, 28 Mar 2020 21:42:54 +0000

[klibc] dash: expand - Fix dangling left square brackets in patterns

[ dash commit ad092191a3f281c2d14089c86757305403a9de64 ]

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:


More information about the klibc mailing list