commit 9964353: [Minor] Allow to call function from stack in rspamd_lua_universal_pcall

Vsevolod Stakhov vsevolod at rspamd.com
Mon Aug 7 12:35:04 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-08-07 13:30:50 +0100
URL: https://github.com/rspamd/rspamd/commit/9964353d374817209248b8b77bceadfb689b4c0b

[Minor] Allow to call function from stack in rspamd_lua_universal_pcall

---
 src/lua/lua_common.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 53473c9dc..d41e69822 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -2555,7 +2555,13 @@ bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc,
 
 	va_start(ap, err);
 	/* Called function */
-	lua_rawgeti(L, LUA_REGISTRYINDEX, cbref);
+	if (cbref > 0) {
+		lua_rawgeti(L, LUA_REGISTRYINDEX, cbref);
+	}
+	else {
+		/* Assume that function was on top of the stack */
+		lua_pushvalue(L, err_idx - 1);
+	}
 	/*
 	 * Possible arguments
 	 * - i - lua_integer, argument - gint64


More information about the Commits mailing list