From df2389900f12cd82d1246490339ef99e62ba13a1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 7 Sep 2023 16:00:56 +0100 Subject: [PATCH] [Minor] Avoid 0 size mallocs --- src/libserver/re_cache.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 171c3d31e..6dd06711b 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -954,17 +954,20 @@ rspamd_re_cache_process_selector(struct rspamd_task *task, lua_rawgeti(L, -1, i + 1); txt = lua_check_text_or_string(L, -1); - if (txt) { + if (txt && txt->len > 0) { sel_data = txt->start; slen = txt->len; + (*svec)[i] = g_malloc(slen); + memcpy((*svec)[i], sel_data, slen); } else { + /* A hack to avoid malloc(0) */ sel_data = ""; slen = 0; + (*svec)[i] = g_malloc(1); + memcpy((*svec)[i], sel_data, 1); } - (*svec)[i] = g_malloc(slen); - memcpy((*svec)[i], sel_data, slen); (*lenvec)[i] = slen; lua_pop(L, 1); } -- 2.39.5