commit 24a0be9: [Minor] Fix re matching when len == 0

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Sep 27 10:21:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-27 11:14:46 +0100
URL: https://github.com/rspamd/rspamd/commit/24a0be9cf3f7aa22160a43e06fa94924b7e7065a (HEAD -> master)

[Minor] Fix re matching when len == 0

---
 src/libutil/map_helpers.c  | 4 ++--
 src/libutil/multipattern.c | 2 +-
 src/lua/lua_regexp.c       | 9 +++++----
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/libutil/map_helpers.c b/src/libutil/map_helpers.c
index 964e4d98c..aaf771b5c 100644
--- a/src/libutil/map_helpers.c
+++ b/src/libutil/map_helpers.c
@@ -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;
diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c
index 363cd800f..6eec009b3 100644
--- a/src/libutil/multipattern.c
+++ b/src/libutil/multipattern.c
@@ -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;
 	}
 
diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c
index 95f40f8f0..a677f7195 100644
--- a/src/lua/lua_regexp.c
+++ b/src/lua/lua_regexp.c
@@ -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) {


More information about the Commits mailing list