]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix crashes on null symbols
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 11:18:30 +0000 (12:18 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 11:18:30 +0000 (12:18 +0100)
src/libserver/symcache/symcache_c.cxx
src/libserver/symcache/symcache_impl.cxx

index d4ebf4be3befcfe243c36fade95b61ae8c254a8c..82ef7c164dbcd154122b8c703d9c8e366591e188 100644 (file)
@@ -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,
index 8da0cbecb86a854d3347779a0fd2a2a0dbee5cbc..25918ce1d051e36aea6dec94299504d02eeaf8f5 100644 (file)
@@ -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;