]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Validate symbols options
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 16 Nov 2019 12:12:05 +0000 (12:12 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 16 Nov 2019 12:12:05 +0000 (12:12 +0000)
src/libmime/scan_result.c

index 2ffe6e7ffaf00d646c1d3aba7cdbb0c065a3ffe5..7b1acd3e91e449ab65b82fac1b5eb52b22546c77 100644 (file)
@@ -21,6 +21,7 @@
 #include "lua/lua_common.h"
 #include "libserver/cfg_file_private.h"
 #include "libmime/scan_result_private.h"
+#include "contrib/fastutf8/fastutf8.h"
 #include <math.h>
 #include "contrib/uthash/utlist.h"
 
@@ -516,7 +517,8 @@ rspamd_task_add_result_option (struct rspamd_task *task,
 {
        struct rspamd_symbol_option *opt;
        gboolean ret = FALSE;
-       gchar *opt_cpy;
+       gchar *opt_cpy = NULL;
+       gsize vlen;
        khiter_t k;
        gint r;
 
@@ -525,6 +527,14 @@ rspamd_task_add_result_option (struct rspamd_task *task,
                        s->options = kh_init (rspamd_options_hash);
                }
 
+               vlen = strlen (val);
+
+               if (!rspamd_fast_utf8_validate (val, vlen)) {
+                       opt_cpy = rspamd_str_make_utf_valid (val, vlen, &vlen,
+                                       task->task_pool);
+                       val = opt_cpy;
+               }
+
                if (!(s->sym && (s->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM)) &&
                                kh_size (s->options) < task->cfg->default_max_shots) {
                        /* Append new options */
@@ -532,7 +542,11 @@ rspamd_task_add_result_option (struct rspamd_task *task,
 
                        if (k == kh_end (s->options)) {
                                opt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*opt));
-                               opt_cpy = rspamd_mempool_strdup (task->task_pool, val);
+
+                               if (opt_cpy == NULL) {
+                                       opt_cpy = rspamd_mempool_strdup (task->task_pool, val);
+                               }
+
                                k = kh_put (rspamd_options_hash, s->options, opt_cpy, &r);
 
                                kh_value (s->options, k) = opt;
@@ -544,7 +558,11 @@ rspamd_task_add_result_option (struct rspamd_task *task,
                }
                else {
                        opt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*opt));
-                       opt_cpy = rspamd_mempool_strdup (task->task_pool, val);
+
+                       if (opt_cpy == NULL) {
+                               opt_cpy = rspamd_mempool_strdup (task->task_pool, val);
+                       }
+
                        k = kh_put (rspamd_options_hash, s->options, opt_cpy, &r);
 
                        kh_value (s->options, k) = opt;