From a00713437a40d512976d4688d270c4866123d678 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sun, 28 May 2017 10:33:57 +0200 Subject: [PATCH] we guess which versions of Lua need help with luaL_setfuncs, and then supply our own. If we guess wrong however, we trample on the Lua namespace. With this commit, we don't do the trampling, which should close #5348. We can improve on the fix by using the native luaL_setfuncs for LuaJIT 2.1 beta too. --- pdns/lua-iputils.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pdns/lua-iputils.cc b/pdns/lua-iputils.cc index c17c8b9f9e..ef2ed86bc1 100644 --- a/pdns/lua-iputils.cc +++ b/pdns/lua-iputils.cc @@ -43,7 +43,7 @@ extern "C" { /* ** Adapted from Lua 5.2.0 */ -static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { +static void pdns_luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup+1, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; @@ -55,6 +55,10 @@ static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { } lua_pop(L, nup); /* remove upvalues */ } +#else +static void pdns_luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { + lual_setfuncs(L, l, nup); +} #endif @@ -261,22 +265,22 @@ extern "C" int luaopen_iputils(lua_State* L) luaL_newmetatable(L, "iputils.ca"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_setfuncs(L, iputils_ca_methods, 0); + pdns_luaL_setfuncs(L, iputils_ca_methods, 0); luaL_newmetatable(L, "iputils.ipset"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_setfuncs(L, ipset_methods, 0); + pdns_luaL_setfuncs(L, ipset_methods, 0); luaL_newmetatable(L, "iputils.netmask"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_setfuncs(L, iputils_netmask_methods, 0); + pdns_luaL_setfuncs(L, iputils_netmask_methods, 0); luaL_newmetatable(L, "iputils.nmgroup"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_setfuncs(L, iputils_nmgroup_methods, 0); + pdns_luaL_setfuncs(L, iputils_nmgroup_methods, 0); #if LUA_VERSION_NUM < 502 luaL_register(L, "iputils", iputils); -- 2.47.2