aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-03-22 17:03:26 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-03-22 17:03:26 +0000
commit05636d9af847923a6f1e538897b085cb3dcdf5d0 (patch)
treec42961e88896cd8fc08c2d3fc769935d5e152705
parent07d9ea28f5b6db84bd55d3115a603e584a1db417 (diff)
downloadrspamd-05636d9af847923a6f1e538897b085cb3dcdf5d0.tar.gz
rspamd-05636d9af847923a6f1e538897b085cb3dcdf5d0.zip
[Minor] Deny zero length in regexp search functions
-rw-r--r--src/libutil/regexp.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c
index b97e66a03..9e98699fe 100644
--- a/src/libutil/regexp.c
+++ b/src/libutil/regexp.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -567,7 +567,8 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len,
g_assert(text != NULL);
if (len == 0) {
- len = strlen(text);
+ /* No length, no match! */
+ return FALSE;
}
if (re->match_limit > 0 && len > re->match_limit) {
@@ -727,7 +728,8 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len,
g_assert(text != NULL);
if (len == 0) {
- len = strlen(text);
+ /* No length, no match! */
+ return FALSE;
}
if (re->match_limit > 0 && len > re->match_limit) {
@@ -948,10 +950,6 @@ rspamd_regexp_match(const rspamd_regexp_t *re, const char *text, gsize len,
g_assert(re != NULL);
g_assert(text != NULL);
- if (len == 0) {
- len = strlen(text);
- }
-
if (rspamd_regexp_search(re, text, len, &start, &end, raw, NULL)) {
if (start == text && end == text + len) {
return TRUE;
@@ -1253,10 +1251,6 @@ rspamd_regexp_from_glob(const char *gl, gsize sz, GError **err)
g_assert(gl != NULL);
- if (sz == 0) {
- sz = strlen(gl);
- }
-
end = gl + sz;
out = g_string_sized_new(sz + 2);
g_string_append_c(out, '^');