Browse Source

[CritFix] Protect regexp matcher from regexps with empty patterns

Issue: #4885
Closes: #4885
pull/4887/head
Vsevolod Stakhov 1 month ago
parent
commit
2038f3c92a
No account linked to committer's email address
3 changed files with 15 additions and 1 deletions
  1. 5
    0
      src/libserver/re_cache.c
  2. 4
    0
      src/libutil/multipattern.c
  3. 6
    1
      src/lua/lua_regexp.c

+ 5
- 0
src/libserver/re_cache.c View File

if (max_hits > 0 && r >= max_hits) { if (max_hits > 0 && r >= max_hits) {
break; break;
} }

if (start >= end) {
/* We found all matches, so no more hits are possible (protect from empty patterns) */
break;
}
} }


rt->results[id] += r; rt->results[id] += r;

+ 4
- 0
src/libutil/multipattern.c View File

&end, &end,
TRUE, TRUE,
NULL)) { NULL)) {
if (start >= end) {
/* We found all matches, so no more hits are possible (protect from empty patterns) */
break;
}
if (rspamd_multipattern_acism_cb(i, end - in, &cbd)) { if (rspamd_multipattern_acism_cb(i, end - in, &cbd)) {
goto out; goto out;
} }

+ 6
- 1
src/lua/lua_regexp.c View File

} }


matched = TRUE; matched = TRUE;

if (start >= end) {
/* We found all matches, so no more hits are possible (protect from empty patterns) */
break;
}
} }


if (!matched) { if (!matched) {
lua_rawseti(L, -2, ++i); lua_rawseti(L, -2, ++i);
matched = TRUE; matched = TRUE;
} }
else if (start == end) {
else if (start >= end) {
break; break;
} }
old_start = end; old_start = end;

Loading…
Cancel
Save