From 0ad8866d6bce92ded9af250e56063f70009bd2dd Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 18 Jan 2013 09:03:57 +0100 Subject: [PATCH] core: fix infinite loop when a regex gives an empty match (bug #38112) --- ChangeLog | 3 ++- src/core/wee-string.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bde70f8ff..7833558fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,13 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.4.0-rc3, 2013-01-17 +v0.4.0-rc3, 2013-01-18 Version 0.4.0 (under dev!) -------------------------- +* core: fix infinite loop when a regex gives an empty match (bug #38112) * core: fix detection of guile in configure * core: fix click in item "buffer_nicklist" when nicklist is a root bar (bug #38080) diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 676de114a..5add7c1fb 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -990,7 +990,13 @@ string_has_highlight_regex_compiled (const char *string, regex_t *regex) while (string && string[0]) { rc = regexec (regex, string, 1, ®ex_match, 0); - if ((rc != 0) || (regex_match.rm_so < 0) || (regex_match.rm_eo < 0)) + + /* + * no match found: exit the loop (if rm_eo == 0, it is an empty match + * at beginning of string: we consider there is no match, to prevent an + * infinite loop) + */ + if ((rc != 0) || (regex_match.rm_so < 0) || (regex_match.rm_eo <= 0)) break; startswith = (regex_match.rm_so == 0);