commit b18ea6a: [Minor] Sigh: add more tolerance to shit that can be passed to symcache API
Vsevolod Stakhov
vsevolod at rspamd.com
Sat May 7 14:56:04 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-05-07 15:54:02 +0100
URL: https://github.com/rspamd/rspamd/commit/b18ea6ab8f82cbe3caaa316ad98a2af37c6d381c (HEAD -> master)
[Minor] Sigh: add more tolerance to shit that can be passed to symcache API
---
src/libserver/symcache/symcache_c.cxx | 42 ++++++++++++++++++++++++++++-
src/libserver/symcache/symcache_runtime.cxx | 3 +--
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx
index 12d888eb1..baec74622 100644
--- a/src/libserver/symcache/symcache_c.cxx
+++ b/src/libserver/symcache/symcache_c.cxx
@@ -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);
}
diff --git a/src/libserver/symcache/symcache_runtime.cxx b/src/libserver/symcache/symcache_runtime.cxx
index 263e35714..e09411845 100644
--- a/src/libserver/symcache/symcache_runtime.cxx
+++ b/src/libserver/symcache/symcache_runtime.cxx
@@ -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;
More information about the Commits
mailing list