commit d17a92c: [Fix] Avoid strdup usage for symbols options

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Feb 6 15:42:14 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-02-06 15:39:47 +0000
URL: https://github.com/rspamd/rspamd/commit/d17a92c24e9d231bb1efe13d4e91280158301b7b (HEAD -> master)

[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;


More information about the Commits mailing list