mirror of https://mirror.osredm.com/root/redis.git
Check length before reading in `stringmatchlen` (#13690)
Fixes four cases where `stringmatchlen` could overrun the pattern if it is not terminated with NUL. These commits are cherry-picked from my [fork](https://github.com/thaliaarchi/antirez-stringmatch) which extracts `stringmatch` as a library and compares it to other projects by antirez which uses the same matcher.
This commit is contained in:
parent
7665bdc91a
commit
8144019a13
10
src/util.c
10
src/util.c
|
@ -109,24 +109,24 @@ static int stringmatchlen_impl(const char *pattern, int patternLen,
|
|||
|
||||
pattern++;
|
||||
patternLen--;
|
||||
not = pattern[0] == '^';
|
||||
not = patternLen && pattern[0] == '^';
|
||||
if (not) {
|
||||
pattern++;
|
||||
patternLen--;
|
||||
}
|
||||
match = 0;
|
||||
while(1) {
|
||||
if (pattern[0] == '\\' && patternLen >= 2) {
|
||||
if (patternLen >= 2 && pattern[0] == '\\') {
|
||||
pattern++;
|
||||
patternLen--;
|
||||
if (pattern[0] == string[0])
|
||||
match = 1;
|
||||
} else if (pattern[0] == ']') {
|
||||
break;
|
||||
} else if (patternLen == 0) {
|
||||
pattern--;
|
||||
patternLen++;
|
||||
break;
|
||||
} else if (pattern[0] == ']') {
|
||||
break;
|
||||
} else if (patternLen >= 3 && pattern[1] == '-') {
|
||||
int start = pattern[0];
|
||||
int end = pattern[2];
|
||||
|
@ -186,7 +186,7 @@ static int stringmatchlen_impl(const char *pattern, int patternLen,
|
|||
pattern++;
|
||||
patternLen--;
|
||||
if (stringLen == 0) {
|
||||
while(*pattern == '*') {
|
||||
while(patternLen && *pattern == '*') {
|
||||
pattern++;
|
||||
patternLen--;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue