From: Vsevolod Stakhov Date: Mon, 21 Oct 2019 15:01:46 +0000 (+0100) Subject: [Fix] Do not use strdup on data extracted from lua X-Git-Tag: 2.1~52 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=10c1e15350a190560eb5b281779d68cbc099bc68;p=rspamd.git [Fix] Do not use strdup on data extracted from lua --- diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 88e346cc5..a9fc2270b 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -855,12 +855,15 @@ rspamd_re_cache_process_selector (struct rspamd_task *task, } else { gsize slen; + const gchar *sel_data; if (lua_type (L, -1) == LUA_TSTRING) { + sel_data = lua_tolstring (L, -1, &slen); *n = 1; *svec = g_malloc (sizeof (guchar *)); *lenvec = g_malloc (sizeof (guint)); - (*svec)[0] = g_strdup (lua_tolstring (L, -1, &slen)); + (*svec)[0] = g_malloc (slen); + memcpy ((*svec)[0], sel_data, slen); (*lenvec)[0] = slen; result = TRUE; @@ -874,7 +877,10 @@ rspamd_re_cache_process_selector (struct rspamd_task *task, for (guint i = 0; i < *n; i ++) { lua_rawgeti (L, -1, i + 1); - (*svec)[i] = g_strdup (lua_tolstring (L, -1, &slen)); + + sel_data = lua_tolstring (L, -1, &slen); + (*svec)[i] = g_malloc (slen); + memcpy ((*svec)[i], sel_data, slen); (*lenvec)[i] = slen; lua_pop (L, 1); }