summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-02-02 13:53:00 +0100
committerJo-Philipp Wich <jo@mein.io>2022-02-03 17:04:05 +0100
commit32d596da36758446331c4202dad9494329545ec2 (patch)
tree87f7cade3c307bb79163f9ebee75a355a9b62c14
parent3e3f38de65f22db4497e0bff3f6b75354ae9463a (diff)
lib: fix infinite loop on empty regexp matches in uc_split()
The regular expression `/()/` will match the empty string, causing the match loop to never advance. Add extra logic to deal with this case, similar to the empty separator string logic. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lib.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index e204ded..6235470 100644
--- a/lib.c
+++ b/lib.c
@@ -927,9 +927,18 @@ uc_split(uc_vm_t *vm, size_t nargs)
if (res == REG_NOMATCH)
break;
- ucv_array_push(arr, ucv_string_new_length(splitstr, pmatch.rm_so));
+ if (pmatch.rm_so != pmatch.rm_eo) {
+ ucv_array_push(arr, ucv_string_new_length(splitstr, pmatch.rm_so));
+ splitstr += pmatch.rm_eo;
+ }
+ else if (*splitstr) {
+ ucv_array_push(arr, ucv_string_new_length(splitstr, 1));
+ splitstr++;
+ }
+ else {
+ goto out;
+ }
- splitstr += pmatch.rm_eo;
eflags |= REG_NOTBOL;
}
@@ -956,6 +965,7 @@ uc_split(uc_vm_t *vm, size_t nargs)
return NULL;
}
+out:
return arr;
}