commit 5fe363b: [Minor] Add sanity check when trying to insert options

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Nov 18 09:35:08 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-11-18 09:34:17 +0000
URL: https://github.com/rspamd/rspamd/commit/5fe363b2ce6705ae2878bf1df3067ef333be1d07 (HEAD -> master)

[Minor] Add sanity check when trying to insert options

---
 src/lua/lua_task.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index e59bd3685..0be4699fe 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1861,27 +1861,48 @@ lua_task_insert_result (lua_State * L)
 				luaL_checkstring (L, args_start));
 		weight = luaL_checknumber (L, args_start + 1);
 		top = lua_gettop (L);
-		s = rspamd_task_insert_result_full (task, symbol_name, weight, NULL, flags);
+		s = rspamd_task_insert_result_full (task, symbol_name, weight,
+				NULL, flags);
 
 		/* Get additional options */
 		if (s) {
 			for (i = args_start + 2; i <= top; i++) {
-				if (lua_type (L, i) == LUA_TSTRING) {
+				gint ltype = lua_type (L, i);
+
+				if (ltype == LUA_TSTRING) {
 					param = luaL_checkstring (L, i);
 					rspamd_task_add_result_option (task, s, param);
 				}
-				else if (lua_type (L, i) == LUA_TTABLE) {
+				else if (ltype == LUA_TTABLE) {
 					lua_pushvalue (L, i);
 					lua_pushnil (L);
 
 					while (lua_next (L, -2)) {
-						param = lua_tostring (L, -1);
-						rspamd_task_add_result_option (task, s, param);
+						if (lua_isstring (L, -1)) {
+							param = lua_tostring (L, -1);
+							rspamd_task_add_result_option (task, s, param);
+						}
+						else {
+							const gchar *tname = lua_typename (L, lua_type (L, -1));
+							lua_pop (L, 2);
+
+							return luaL_error (L, "not a string option in a table "
+												  "when adding symbol  %s: %s type",
+									s->name, tname);
+						}
+
 						lua_pop (L, 1);
 					}
 
 					lua_pop (L, 1);
 				}
+				else {
+					const gchar *tname = lua_typename (L, ltype);
+
+					return luaL_error (L, "not a string/table option "
+										  "when adding symbol %s: %s type",
+							s->name, tname);
+				}
 			}
 		}
 


More information about the Commits mailing list