Skip to content

Commit

Permalink
fix out of range string_view access
Browse files Browse the repository at this point in the history
  • Loading branch information
etam committed Apr 14, 2024
1 parent 1083369 commit 050ddf7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/globpath.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ MatchResult GlobPath::match_cclass(size_t *pattern_pos, const char &pathchar)
} else if (this->pattern[nextpat] == pathchar) {
found = true;
}
nextpat++;
if (++nextpat >= this->patlen)
return MatchResult::Invalid;
} while (this->pattern[nextpat] != ']');

// Range has ended preliminary (like eg. "[a-]") so we need to match the
Expand Down Expand Up @@ -157,7 +158,7 @@ MatchResult GlobPath::match_norec(size_t *pattern_pos, size_t *path_pos)
if (this->pattern[patpos] == '*') {
size_t anum;
// Eat up all consecutive "any string" wildcard characters.
for (anum = 0; this->pattern[patpos] == '*'; ++anum) {
for (anum = 0; patpos < this->patlen && this->pattern[patpos] == '*'; ++anum) {
// If the wildcard is the last character in pattern, anything
// from the rest of path will match.
if (patpos >= this->patlen) {
Expand All @@ -171,7 +172,7 @@ MatchResult GlobPath::match_norec(size_t *pattern_pos, size_t *path_pos)

// If the number of asterisks is two followed by a slash, we need
// to do recursive globbing, like eg. "a/**/b" or "**/foo".
bool is_slash = this->pattern[patpos] == '/';
bool is_slash = patpos < this->patlen && this->pattern[patpos] == '/';
if (anum == 2 && last_slash + 2 == patpos && is_slash) {
*pattern_pos = patpos + 1;
*path_pos = pathpos;
Expand Down Expand Up @@ -201,7 +202,7 @@ MatchResult GlobPath::match_norec(size_t *pattern_pos, size_t *path_pos)

MatchResult result = this->match_fixed(&patpos, &pathpos);
if (result == MatchResult::GotSlash) {
if (this->pattern[patpos++] == '/') {
if (patpos < this->patlen && this->pattern[patpos++] == '/') {
last_slash = patpos;
pathpos++;
} else {
Expand Down

0 comments on commit 050ddf7

Please sign in to comment.