commit 3c461d3: [Minor] Add some fail-safety

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Aug 18 15:07:07 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-08-18 16:06:21 +0100
URL: https://github.com/rspamd/rspamd/commit/3c461d3ef5bd61514a3d20d0927f5791c2a8be2f (HEAD -> master)

[Minor] Add some fail-safety

---
 src/lua/lua_task.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 27fee395d..09479ea21 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -4732,6 +4732,12 @@ lua_task_get_groups (lua_State *L)
 			mres = rspamd_find_metric_result (task, lua_tostring (L, 3));
 		}
 
+		if (mres == NULL) {
+			lua_pushnil (L);
+
+			return 1;
+		}
+
 		lua_createtable (L, 0, kh_size (mres->sym_groups));
 
 		kh_foreach (mres->sym_groups, gr, gr_score, {
@@ -5943,6 +5949,12 @@ lua_task_get_metric_result (lua_State *L)
 
 		if (lua_isstring (L, 2)) {
 			metric_res = rspamd_find_metric_result (task, lua_tostring (L, 2));
+
+			if (metric_res == NULL) {
+				lua_pushnil (L);
+
+				return 1;
+			}
 		}
 
 		/* Fields added:
@@ -6043,6 +6055,12 @@ lua_task_get_metric_action (lua_State *L)
 			mres = rspamd_find_metric_result (task, lua_tostring (L, 2));
 		}
 
+		if (mres == NULL) {
+			lua_pushnil (L);
+
+			return 1;
+		}
+
 		action = rspamd_check_action_metric (task, NULL, mres);
 		lua_pushstring (L, action->name);
 	}


More information about the Commits mailing list