summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-05-19 17:18:43 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-05-19 17:18:43 +0100
commit13a13b60f155603393c5575ccfdeaa877cb613b6 (patch)
tree50d47f0d708d1b41dedb758928c7073f29c9a105 /src
parenta102caecf7ab481bf4f3f5f4a233a5e64467e4d2 (diff)
downloadrspamd-13a13b60f155603393c5575ccfdeaa877cb613b6.tar.gz
rspamd-13a13b60f155603393c5575ccfdeaa877cb613b6.zip
[Minor] Add `max_recipients` config knob
Diffstat (limited to 'src')
-rw-r--r--src/libmime/email_addr.c2
-rw-r--r--src/libmime/email_addr.h4
-rw-r--r--src/libmime/mime_headers.c11
-rw-r--r--src/libserver/cfg_file.h1
-rw-r--r--src/libserver/cfg_rcl.c6
-rw-r--r--src/libserver/cfg_utils.c1
-rw-r--r--src/libserver/milter.c8
-rw-r--r--src/libserver/protocol.c6
8 files changed, 23 insertions, 16 deletions
diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c
index 1987c58c3..eaf44fc91 100644
--- a/src/libmime/email_addr.c
+++ b/src/libmime/email_addr.c
@@ -48,7 +48,7 @@ rspamd_email_address_unescape (struct rspamd_email_address *addr)
}
struct rspamd_email_address *
-rspamd_email_address_from_smtp (const gchar *str, guint len, gint max_elements)
+rspamd_email_address_from_smtp (const gchar *str, guint len)
{
struct rspamd_email_address addr, *ret;
gsize nlen;
diff --git a/src/libmime/email_addr.h b/src/libmime/email_addr.h
index 2452fc7aa..fe9fd9e9d 100644
--- a/src/libmime/email_addr.h
+++ b/src/libmime/email_addr.h
@@ -67,9 +67,7 @@ struct rspamd_task;
* @param len length of string
* @return
*/
-struct rspamd_email_address *rspamd_email_address_from_smtp (const gchar *str,
- guint len,
- gint max_elements);
+struct rspamd_email_address *rspamd_email_address_from_smtp (const gchar *str, guint len);
/**
* Parses email address from the mime header, decodes names and return the array
diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c
index 55d04d69a..786d43a6a 100644
--- a/src/libmime/mime_headers.c
+++ b/src/libmime/mime_headers.c
@@ -20,6 +20,7 @@
#include "contrib/uthash/utlist.h"
#include "libserver/mempool_vars_internal.h"
#include "libserver/url.h"
+#include "libserver/cfg_file.h"
#include "libutil/util.h"
#include <unicode/utf8.h>
@@ -62,25 +63,25 @@ rspamd_mime_header_check_special (struct rspamd_task *task,
case 0x76F31A09F4352521ULL: /* to */
MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, rcpt_mime), -1);
+ MESSAGE_FIELD (task, rcpt_mime), task->cfg->max_recipients);
rh->flags |= RSPAMD_HEADER_TO|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
break;
case 0x7EB117C1480B76ULL: /* cc */
MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, rcpt_mime), -1);
+ MESSAGE_FIELD (task, rcpt_mime), task->cfg->max_recipients);
rh->flags |= RSPAMD_HEADER_CC|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
break;
case 0xE4923E11C4989C8DULL: /* bcc */
MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, rcpt_mime), -1);
+ MESSAGE_FIELD (task, rcpt_mime), task->cfg->max_recipients);
rh->flags |= RSPAMD_HEADER_BCC|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
break;
case 0x41E1985EDC1CBDE4ULL: /* from */
MESSAGE_FIELD (task, from_mime) = rspamd_email_address_from_mime (task->task_pool,
rh->decoded, strlen (rh->decoded),
- MESSAGE_FIELD (task, from_mime), -1);
+ MESSAGE_FIELD (task, from_mime), task->cfg->max_recipients);
rh->flags |= RSPAMD_HEADER_FROM|RSPAMD_HEADER_SENDER|RSPAMD_HEADER_UNIQUE;
break;
case 0x43A558FC7C240226ULL: /* message-id */ {
@@ -129,7 +130,7 @@ rspamd_mime_header_check_special (struct rspamd_task *task,
case 0xEE4AA2EAAC61D6F4ULL: /* return-path */
if (task->from_envelope == NULL) {
task->from_envelope = rspamd_email_address_from_smtp (rh->decoded,
- strlen (rh->decoded), -1);
+ strlen (rh->decoded));
}
rh->flags = RSPAMD_HEADER_RETURN_PATH|RSPAMD_HEADER_UNIQUE;
break;
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 702325f62..5c6c682a1 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -471,6 +471,7 @@ struct rspamd_config {
guint full_gc_iters; /**< iterations between full gc cycle */
guint max_lua_urls; /**< maximum number of urls to be passed to Lua */
guint max_urls; /**< maximum number of urls to be processed in general */
+ gint max_recipients; /**< maximum number of recipients to be processed */
guint max_blas_threads; /**< maximum threads for openblas when learning ANN */
guint max_opts_len; /**< maximum length for all options for a symbol */
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index dc568297b..885ebad4d 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -2241,6 +2241,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg, GHashTable *skip_sections)
RSPAMD_CL_FLAG_INT_32,
"Maximum count of URLs to process to avoid DoS (default: 10240)");
rspamd_rcl_add_default_handler (sub,
+ "max_recipients",
+ rspamd_rcl_parse_struct_integer,
+ G_STRUCT_OFFSET (struct rspamd_config, max_recipients),
+ RSPAMD_CL_FLAG_INT_32,
+ "Maximum count of recipients to process to avoid DoS (default: 1024)");
+ rspamd_rcl_add_default_handler (sub,
"max_blas_threads",
rspamd_rcl_parse_struct_integer,
G_STRUCT_OFFSET (struct rspamd_config, max_blas_threads),
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index d3ad9e210..6b3f3e15b 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -221,6 +221,7 @@ rspamd_config_new (enum rspamd_config_init_flags flags)
cfg->cache_reload_time = 30.0;
cfg->max_lua_urls = 1024;
cfg->max_urls = cfg->max_lua_urls * 10;
+ cfg->max_recipients = 1024;
cfg->max_blas_threads = 1;
cfg->max_opts_len = 4096;
diff --git a/src/libserver/milter.c b/src/libserver/milter.c
index 4713b7371..dc398912d 100644
--- a/src/libserver/milter.c
+++ b/src/libserver/milter.c
@@ -603,7 +603,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
cpy = rspamd_mempool_alloc (priv->pool, zero - pos);
memcpy (cpy, pos, zero - pos);
msg_debug_milter ("got mail: %*s", (int)(zero - pos), cpy);
- addr = rspamd_email_address_from_smtp (cpy, zero - pos, -1);
+ addr = rspamd_email_address_from_smtp (cpy, zero - pos);
if (addr) {
session->from = addr;
@@ -618,7 +618,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
/* That actually should not happen */
cpy = rspamd_mempool_alloc (priv->pool, end - pos);
memcpy (cpy, pos, end - pos);
- addr = rspamd_email_address_from_smtp (cpy, end - pos, -1);
+ addr = rspamd_email_address_from_smtp (cpy, end - pos);
if (addr) {
session->from = addr;
@@ -707,7 +707,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
memcpy (cpy, pos, end - pos);
msg_debug_milter ("got rcpt: %*s", (int)(zero - pos), cpy);
- addr = rspamd_email_address_from_smtp (cpy, zero - pos, -1);
+ addr = rspamd_email_address_from_smtp (cpy, zero - pos);
if (addr) {
if (!session->rcpts) {
@@ -726,7 +726,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
msg_debug_milter ("got weird rcpt: %*s", (int)(end - pos),
pos);
/* That actually should not happen */
- addr = rspamd_email_address_from_smtp (cpy, end - pos, -1);
+ addr = rspamd_email_address_from_smtp (cpy, end - pos);
if (addr) {
if (!session->rcpts) {
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 1d51ff28f..9d1276064 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -292,7 +292,7 @@ rspamd_protocol_process_recipients (struct rspamd_task *task,
else if (*p == ',' && start_addr != NULL && p > start_addr) {
/* We have finished address, check what we have */
addr = rspamd_email_address_from_smtp (start_addr,
- p - start_addr, -1);
+ p - start_addr);
if (addr) {
if (task->rcpt_envelope == NULL) {
@@ -322,7 +322,7 @@ rspamd_protocol_process_recipients (struct rspamd_task *task,
if (start_addr && p > start_addr) {
switch (state) {
case normal_string:
- addr = rspamd_email_address_from_smtp (start_addr, end - start_addr, -1);
+ addr = rspamd_email_address_from_smtp (start_addr, end - start_addr);
if (addr) {
if (task->rcpt_envelope == NULL) {
@@ -495,7 +495,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
IF_HEADER (FROM_HEADER) {
task->from_envelope = rspamd_email_address_from_smtp (
hv_tok->begin,
- hv_tok->len, -1);
+ hv_tok->len);
msg_debug_protocol ("read from header, value: %T", hv_tok);
if (!task->from_envelope) {