]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Sigh: add more tolerance to shit that can be passed to symcache API
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 14:54:02 +0000 (15:54 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 14:54:02 +0000 (15:54 +0100)
src/libserver/symcache/symcache_c.cxx
src/libserver/symcache/symcache_runtime.cxx

index 12d888eb17180aa642a11e872fb3d7cd993a337e..baec746226df19b3cee1706406238e44dd5c1dc5 100644 (file)
@@ -230,6 +230,11 @@ const gchar *
 rspamd_symcache_item_name(struct rspamd_symcache_item *item)
 {
        auto *real_item = C_API_SYMCACHE_ITEM(item);
+
+       if (real_item == nullptr) {
+               return 0;
+       }
+
        return real_item->get_name().c_str();
 }
 
@@ -237,6 +242,11 @@ gint
 rspamd_symcache_item_flags(struct rspamd_symcache_item *item)
 {
        auto *real_item = C_API_SYMCACHE_ITEM(item);
+
+       if (real_item == nullptr) {
+               return 0;
+       }
+
        return real_item->get_flags();
 }
 
@@ -376,6 +386,10 @@ rspamd_symcache_disable_symbol(struct rspamd_task *task,
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
        auto *real_cache = C_API_SYMCACHE(cache);
 
+       if (cache_runtime == nullptr) {
+               return FALSE;
+       }
+
        return cache_runtime->disable_symbol(task, *real_cache, symbol);
 }
 
@@ -387,6 +401,10 @@ rspamd_symcache_enable_symbol(struct rspamd_task *task,
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
        auto *real_cache = C_API_SYMCACHE(cache);
 
+       if (cache_runtime == nullptr) {
+               return FALSE;
+       }
+
        return cache_runtime->enable_symbol(task, *real_cache, symbol);
 }
 
@@ -398,6 +416,10 @@ rspamd_symcache_is_checked(struct rspamd_task *task,
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
        auto *real_cache = C_API_SYMCACHE(cache);
 
+       if (cache_runtime == nullptr) {
+               return FALSE;
+       }
+
        return cache_runtime->is_symbol_checked(*real_cache, symbol);
 }
 
@@ -408,6 +430,10 @@ rspamd_symcache_process_settings(struct rspamd_task *task,
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
        auto *real_cache = C_API_SYMCACHE(cache);
 
+       if (cache_runtime == nullptr) {
+               return FALSE;
+       }
+
        return cache_runtime->process_settings(task, *real_cache);
 }
 
@@ -418,6 +444,10 @@ rspamd_symcache_is_item_allowed(struct rspamd_task *task,
 {
        auto *real_item = C_API_SYMCACHE_ITEM(item);
 
+       if (real_item == nullptr) {
+               return TRUE;
+       }
+
        return real_item->is_allowed(task, exec_only);
 }
 
@@ -430,7 +460,6 @@ rspamd_symcache_is_symbol_enabled(struct rspamd_task *task,
        auto *real_cache = C_API_SYMCACHE(cache);
 
        if (!cache_runtime) {
-               /* XXX: ugly hack to enable classification during learning... */
                return TRUE;
        }
 
@@ -442,6 +471,10 @@ rspamd_symcache_get_cur_item(struct rspamd_task *task)
 {
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
 
+       if (!cache_runtime) {
+               return nullptr;
+       }
+
        return (struct rspamd_symcache_item *) cache_runtime->get_cur_item();
 }
 
@@ -451,6 +484,10 @@ rspamd_symcache_set_cur_item(struct rspamd_task *task, struct rspamd_symcache_it
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
        auto *real_item = C_API_SYMCACHE_ITEM(item);
 
+       if (!cache_runtime || !real_item) {
+               return nullptr;
+       }
+
        return (struct rspamd_symcache_item *) cache_runtime->set_cur_item(real_item);
 }
 
@@ -458,6 +495,9 @@ void
 rspamd_symcache_enable_profile(struct rspamd_task *task)
 {
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
+       if (!cache_runtime) {
+               return;
+       }
 
        cache_runtime->set_profile_mode(true);
 }
index 263e3571480b029a945818bec58c0ed6426a9df9..e0941184536860705e4aa2e3e937b8ac6ca1604d 100644 (file)
@@ -509,13 +509,12 @@ symcache_runtime::process_symbol(struct rspamd_task *task, symcache &cache, cach
                        dyn_item->start_msec = (ev_now(task->event_loop) -
                                                                        profile_start) * 1e3;
                }
-
                dyn_item->async_events = 0;
                cur_item = item;
                items_inflight++;
                /* Callback now must finalize itself */
                item->call(task);
-               cur_item = NULL;
+               cur_item = nullptr;
 
                if (items_inflight == 0) {
                        return true;