diff --git a/libclamav/regex_suffix.c b/libclamav/regex_suffix.c index 1a2867b6f..1952eb6c8 100644 --- a/libclamav/regex_suffix.c +++ b/libclamav/regex_suffix.c @@ -274,7 +274,7 @@ static struct node *parse_regex(const uint8_t *p, const size_t pSize, size_t *la struct node *right; struct node *tmp; - while (p[*last] != '$' && p[*last] != '\0') { + while (*last < pSize && p[*last] != '$' && p[*last] != '\0') { switch (p[*last]) { case '|': ++*last; @@ -356,6 +356,7 @@ static struct node *parse_regex(const uint8_t *p, const size_t pSize, size_t *la ++*last; /* fall-through */ default: + if (*last >= pSize) break; right = make_leaf(p[*last]); v = make_node(concat, v, right); if (!v) {