From d17a92c24e9d231bb1efe13d4e91280158301b7b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 6 Feb 2020 15:39:47 +0000 Subject: [PATCH] [Fix] Avoid strdup usage for symbols options --- src/libmime/scan_result.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c index 671e99a9b..b9eb882b2 100644 --- a/src/libmime/scan_result.c +++ b/src/libmime/scan_result.c @@ -550,17 +550,18 @@ rspamd_task_add_result_option (struct rspamd_task *task, k = kh_get (rspamd_options_hash, s->options, &srch); if (k == kh_end (s->options)) { - opt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*opt)); + gchar *dst_cpy; - if (opt_cpy == NULL) { - opt_cpy = rspamd_mempool_strdup (task->task_pool, val); - } + opt = rspamd_mempool_alloc0 (task->task_pool, + sizeof (*opt) + vlen + 1); + dst_cpy = ((gchar *)opt) + sizeof (*opt); + memcpy (dst_cpy, val, vlen); + dst_cpy[vlen] = '\0'; opt->optlen = vlen; - opt->option = opt_cpy; + opt->option = dst_cpy; - k = kh_put (rspamd_options_hash, s->options, opt, &r); - opt->option = opt_cpy; + kh_put (rspamd_options_hash, s->options, opt, &r); DL_APPEND (s->opts_head, opt); ret = TRUE; -- 2.39.5