Browse Source

[Minor] Fix re matching when len == 0

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
24a0be9cf3
3 changed files with 8 additions and 7 deletions
  1. 2
    2
      src/libutil/map_helpers.c
  2. 1
    1
      src/libutil/multipattern.c
  3. 5
    4
      src/lua/lua_regexp.c

+ 2
- 2
src/libutil/map_helpers.c View File

@@ -1252,12 +1252,12 @@ rspamd_match_regexp_map_all (struct rspamd_regexp_map_helper *map,
gboolean validated = FALSE;
struct rspamd_map_helper_value *val;

g_assert (in != NULL);

if (map == NULL || map->regexps == NULL || len == 0) {
return NULL;
}

g_assert (in != NULL);

if (map->map_flags & RSPAMD_REGEXP_MAP_FLAG_UTF) {
if (g_utf8_validate (in, len, NULL)) {
validated = TRUE;

+ 1
- 1
src/libutil/multipattern.c View File

@@ -611,7 +611,7 @@ rspamd_multipattern_lookup (struct rspamd_multipattern *mp,

g_assert (mp != NULL);

if (mp->cnt == 0 || !mp->compiled) {
if (mp->cnt == 0 || !mp->compiled || len == 0) {
return 0;
}


+ 5
- 4
src/lua/lua_regexp.c View File

@@ -543,7 +543,7 @@ lua_regexp_search (lua_State *L)
raw = lua_toboolean (L, 3);
}

if (data) {
if (data && len > 0) {
if (lua_gettop (L) >= 4) {
capture = TRUE;
captures = g_array_new (FALSE, TRUE,
@@ -633,7 +633,7 @@ lua_regexp_match (lua_State *L)
raw = lua_toboolean (L, 3);
}

if (data) {
if (data && len > 0) {
if (re->match_limit > 0) {
len = MIN (len, re->match_limit);
}
@@ -694,7 +694,7 @@ lua_regexp_matchn (lua_State *L)
raw = lua_toboolean (L, 4);
}

if (data) {
if (data && len > 0) {
matches = 0;

if (re->match_limit > 0) {
@@ -770,10 +770,11 @@ lua_regexp_split (lua_State *L)
len = MIN (len, re->match_limit);
}

if (data) {
if (data && len > 0) {
lua_newtable (L);
i = 0;
old_start = data;

while (rspamd_regexp_search (re->re, data, len, &start, &end, FALSE,
NULL)) {
if (start - old_start > 0) {

Loading…
Cancel
Save