diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-02-02 13:53:00 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-02-03 17:04:05 +0100 |
commit | 32d596da36758446331c4202dad9494329545ec2 (patch) | |
tree | 87f7cade3c307bb79163f9ebee75a355a9b62c14 /lib.c | |
parent | 3e3f38de65f22db4497e0bff3f6b75354ae9463a (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>
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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; } |