aboutsummaryrefslogtreecommitdiff
path: root/url-mode.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2025-02-10 07:54:42 +0000
committerDaniel Eklöf <daniel@ekloef.se>2025-02-10 07:54:42 +0000
commit98db9658136cfc41b496b005c9df537f59aed6b8 (patch)
treea4fadc62ae15c05bbdd57a857a9ecdb279fd260a /url-mode.c
parentFix URL detection regression on lines with NUL bytes (diff)
url-mode: terminate last virtual line before regex matching
If the last line doesn't have a hard linebreak, it was never NULL terminated, causing regexec() to crash on an out-of-bounds access.
Diffstat (limited to 'url-mode.c')
-rw-r--r--url-mode.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/url-mode.c b/url-mode.c
index 6fd7f03a..00d38d75 100644
--- a/url-mode.c
+++ b/url-mode.c
@@ -388,10 +388,14 @@ regex_detected(const struct terminal *term, enum url_action action,
}
}
+ /* Terminate the last line, if necessary */
+ if (vline->len > 0 && vline->utf8[vline->len - 1] != '\0')
+ vline->utf8[vline->len++] = '\0';
+
for (size_t i = 0; i < ALEN(vlines); i++) {
const struct vline *v = &vlines[i];
if (v->utf8 == NULL)
- continue;;
+ continue;
const char *search_string = v->utf8;
while (true) {