From 3b034b84d9d42e07799e2267a8918049e6e4a232 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 29 Nov 2023 13:43:02 +0000 Subject: [PATCH] Fix null pointer arithmetic UB in libregexp (#136) This is a patch I originally wrote for the Kiesel JS engine: https://codeberg.org/kiesel-js/kiesel/src/branch/main/patches/libregexp.patch --- libregexp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libregexp.c b/libregexp.c index d4df2f8..624538d 100644 --- a/libregexp.c +++ b/libregexp.c @@ -1199,9 +1199,10 @@ static int find_group_name(REParseState *s, const char *name) size_t len, name_len; int capture_index; - name_len = strlen(name); p = (char *)s->group_names.buf; + if (!p) return -1; buf_end = (char *)s->group_names.buf + s->group_names.size; + name_len = strlen(name); capture_index = 1; while (p < buf_end) { len = strlen(p);