commit 10c1e15: [Fix] Do not use strdup on data extracted from lua
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Oct 21 15:07:08 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-10-21 16:01:46 +0100
URL: https://github.com/rspamd/rspamd/commit/10c1e15350a190560eb5b281779d68cbc099bc68 (HEAD -> master)
[Fix] Do not use strdup on data extracted from lua
---
src/libserver/re_cache.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
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);
}
More information about the Commits
mailing list