]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Avoid 0 size mallocs
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 7 Sep 2023 15:00:56 +0000 (16:00 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 7 Sep 2023 15:00:56 +0000 (16:00 +0100)
src/libserver/re_cache.c

index 171c3d31e004b0a78cda00ca9f4de4c0dc9f8e40..6dd06711b0c60a0b0768b22e53f4414ea7d1840a 100644 (file)
@@ -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);
                                }