diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-09-07 16:00:56 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-09-07 16:00:56 +0100 |
commit | df2389900f12cd82d1246490339ef99e62ba13a1 (patch) | |
tree | 9ebc51d179c2be024c978bdb90f06f5aae0bd2a6 | |
parent | 7ee372d24b5dcc4e8fcd7cf02126e13ccaf897b5 (diff) | |
download | rspamd-df2389900f12cd82d1246490339ef99e62ba13a1.tar.gz rspamd-df2389900f12cd82d1246490339ef99e62ba13a1.zip |
[Minor] Avoid 0 size mallocs
-rw-r--r-- | src/libserver/re_cache.c | 9 |
1 files 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); } |