From f079ea198efe3671c61f4fa366fda925762c2a39 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 7 May 2022 12:18:30 +0100 Subject: [PATCH] [Minor] Fix crashes on null symbols --- src/libserver/symcache/symcache_c.cxx | 16 ++++++++++++++-- src/libserver/symcache/symcache_impl.cxx | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index d4ebf4be3..82ef7c164 100644 --- a/src/libserver/symcache/symcache_c.cxx +++ b/src/libserver/symcache/symcache_c.cxx @@ -70,6 +70,11 @@ rspamd_symcache_add_symbol(struct rspamd_symcache *cache, { auto *real_cache = C_API_SYMCACHE(cache); + /* Legacy stuff */ + if (name == nullptr) { + name = ""; + } + if (parent == -1) { return real_cache->add_symbol_with_callback(name, priority, func, user_data, type); } @@ -97,11 +102,17 @@ rspamd_symcache_add_condition_delayed(struct rspamd_symcache *cache, return TRUE; } -gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache, +gint +rspamd_symcache_find_symbol(struct rspamd_symcache *cache, const gchar *name) { auto *real_cache = C_API_SYMCACHE(cache); + /* Legacy stuff but used */ + if (name == nullptr) { + return -1; + } + auto sym_maybe = real_cache->get_item_by_name(name, false); if (sym_maybe != nullptr) { @@ -111,7 +122,8 @@ gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache, return -1; } -gboolean rspamd_symcache_stat_symbol(struct rspamd_symcache *cache, +gboolean +rspamd_symcache_stat_symbol(struct rspamd_symcache *cache, const gchar *name, gdouble *frequency, gdouble *freq_stddev, diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx index 8da0cbecb..25918ce1d 100644 --- a/src/libserver/symcache/symcache_impl.cxx +++ b/src/libserver/symcache/symcache_impl.cxx @@ -623,7 +623,9 @@ auto symcache::add_symbol_with_callback(std::string_view name, std::string static_string_name; if (name.empty()) { - static_string_name = fmt::format("AUTO_{}", (void *) func); + static_string_name = fmt::format("AUTO_{}_{}", (void *)func, user_data); + msg_warn_cache("trying to add an empty symbol name, convert it to %s", + static_string_name.c_str()); } else { static_string_name = name; -- 2.39.5