From: Vsevolod Stakhov Date: Thu, 7 Sep 2023 15:00:56 +0000 (+0100) Subject: [Minor] Avoid 0 size mallocs X-Git-Tag: 3.7.1~52 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=df2389900f12cd82d1246490339ef99e62ba13a1;p=rspamd.git [Minor] Avoid 0 size mallocs --- 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); }