]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to call function from stack in rspamd_lua_universal_pcall
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 7 Aug 2023 12:30:50 +0000 (13:30 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 7 Aug 2023 12:30:50 +0000 (13:30 +0100)
src/lua/lua_common.c

index 53473c9dc7affa7106e45e7edcba3072409914b1..d41e69822ea0280b7d3a1dba5da9c5b76046abfb 100644 (file)
@@ -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