summaryrefslogtreecommitdiffstats
path: root/bin/sh/expand.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2015-09-13 13:58:46 +0000
committerjilles <jilles@FreeBSD.org>2015-09-13 13:58:46 +0000
commit4c6f14a861a3f125cf0a54644a95aaa138e549db (patch)
treefd23eeaf39e5fc47af49dbefaf2a9ee7712c07ed /bin/sh/expand.c
parent4918e13c30a266fdc74a5df487939a8cea9745fb (diff)
downloadFreeBSD-src-4c6f14a861a3f125cf0a54644a95aaa138e549db.zip
FreeBSD-src-4c6f14a861a3f125cf0a54644a95aaa138e549db.tar.gz
MFC r287148: sh: Fix out of bounds read when there is no ] after a [:class:].
The initial check for a matching ] was incorrect if a ] may be consumed by a [:class:]. The subsequent loop assumed that there must be a ]. Remove the initial check and make the loop cope with a missing ]. Found with afl-fuzz.
Diffstat (limited to 'bin/sh/expand.c')
-rw-r--r--bin/sh/expand.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 7c68dca..84e342d 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -1468,21 +1468,11 @@ patmatch(const char *pattern, const char *string, int squoted)
bt_q = q;
break;
case '[': {
- const char *endp;
+ const char *savep, *saveq;
int invert, found;
wchar_t chr;
- endp = p;
- if (*endp == '!' || *endp == '^')
- endp++;
- do {
- while (*endp == CTLQUOTEMARK)
- endp++;
- if (*endp == 0)
- goto dft; /* no matching ] */
- if (*endp == CTLESC)
- endp++;
- } while (*++endp != ']');
+ savep = p, saveq = q;
invert = 0;
if (*p == '!' || *p == '^') {
invert++;
@@ -1501,6 +1491,11 @@ patmatch(const char *pattern, const char *string, int squoted)
chr = (unsigned char)*q++;
c = *p++;
do {
+ if (c == '\0') {
+ p = savep, q = saveq;
+ c = '[';
+ goto dft;
+ }
if (c == CTLQUOTEMARK)
continue;
if (c == '[' && *p == ':') {
OpenPOWER on IntegriCloud