From ab4426f9873eee6d83871f9bd03d2d64a5f862b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 31 Jan 2025 13:10:58 +0100 Subject: [PATCH] url-mode: regex: make sure there's always room for the NULL terminator --- url-mode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/url-mode.c b/url-mode.c index 9ba07d14..5b74771a 100644 --- a/url-mode.c +++ b/url-mode.c @@ -354,7 +354,8 @@ regex_detected(const struct terminal *term, enum url_action action, url_list_t * for (size_t j = 0; j < char_len; j++) { const size_t requires_size = vline->len + char_len; - if (requires_size > vline->sz) { + /* Need to grow? Remember to save at least one byte for terminator */ + if (vline->sz == 0 || requires_size > vline->sz - 1) { const size_t new_size = requires_size * 2; vline->utf8 = xreallocarray(vline->utf8, new_size, 1); vline->map = xreallocarray(vline->map, new_size, sizeof(vline->map[0]));