Skip to content

Commit

Permalink
lib: fix infinite loop on empty regexp matches in uc_match()
Browse files Browse the repository at this point in the history
The regular expression `/()/` will match the empty string, causing the
match loop to never advance. Add extra logic to deal with this case.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Feb 3, 2022
1 parent 32d596d commit 3ad57f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib.c
Expand Up @@ -1804,7 +1804,13 @@ uc_match(uc_vm_t *vm, size_t nargs)

ucv_array_push(rv, m);

p += pmatch[0].rm_eo;
if (pmatch[0].rm_so != pmatch[0].rm_eo)
p += pmatch[0].rm_eo;
else if (*p)
p++;
else
break;

eflags |= REG_NOTBOL;
}
else {
Expand Down

0 comments on commit 3ad57f1

Please sign in to comment.