From 47ddd46d9ae76338e26a07b4a9250ea6b1ceb126 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Mon, 15 Sep 2025 09:18:33 +0200 Subject: [PATCH] Widen the try block in luaSynth to catch the lua_report() exception. It may fire if the lua-records-exec-limit value is really, really, really small. Signed-off-by: Miod Vallat --- pdns/lua-record.cc | 72 +++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index cc8c235ec..5e7f872da 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -1761,46 +1761,46 @@ static void setupLuaRecords(LuaContext& lua) std::vector> luaSynth(const std::string& code, const DNSName& query, const DNSZoneRecord& zone_record, const DNSName& zone, const DNSPacket& dnsp, uint16_t qtype, unique_ptr& LUA) { - if(!LUA || // we don't have a Lua state yet - !g_LuaRecordSharedState) { // or we want a new one even if we had one - LUA = make_unique(::arg()["lua-global-include-dir"]); - setupLuaRecords(*LUA->getLua()); - } - std::vector> ret; - LuaContext& lua = *LUA->getLua(); - - s_lua_record_ctx = std::make_unique(); - s_lua_record_ctx->qname = query; - s_lua_record_ctx->zone_record = zone_record; - s_lua_record_ctx->zone = zone; - s_lua_record_ctx->remote = dnsp.getRealRemote(); - - lua.writeVariable("qname", query); - lua.writeVariable("zone", zone); - lua.writeVariable("zoneid", zone_record.domain_id); - lua.writeVariable("who", dnsp.getInnerRemote()); - lua.writeVariable("localwho", dnsp.getLocal()); - lua.writeVariable("dh", (dnsheader*)&dnsp.d); - lua.writeVariable("dnssecOK", dnsp.d_dnssecOk); - lua.writeVariable("tcp", dnsp.d_tcp); - lua.writeVariable("ednsPKTSize", dnsp.d_ednsRawPacketSizeLimit); - if(dnsp.hasEDNSSubnet()) { - lua.writeVariable("ecswho", dnsp.getRealRemote()); - s_lua_record_ctx->bestwho = dnsp.getRealRemote().getNetwork(); - } - else { - lua.writeVariable("ecswho", nullptr); - s_lua_record_ctx->bestwho = dnsp.getInnerRemote(); - } - lua.writeVariable("bestwho", s_lua_record_ctx->bestwho); + try { + if(!LUA || // we don't have a Lua state yet + !g_LuaRecordSharedState) { // or we want a new one even if we had one + LUA = make_unique(::arg()["lua-global-include-dir"]); + setupLuaRecords(*LUA->getLua()); + } - if (g_luaRecordExecLimit > 0) { - lua.executeCode(boost::str(boost::format("debug.sethook(report, '', %d)") % g_luaRecordExecLimit)); - } + LuaContext& lua = *LUA->getLua(); + + s_lua_record_ctx = std::make_unique(); + s_lua_record_ctx->qname = query; + s_lua_record_ctx->zone_record = zone_record; + s_lua_record_ctx->zone = zone; + s_lua_record_ctx->remote = dnsp.getRealRemote(); + + lua.writeVariable("qname", query); + lua.writeVariable("zone", zone); + lua.writeVariable("zoneid", zone_record.domain_id); + lua.writeVariable("who", dnsp.getInnerRemote()); + lua.writeVariable("localwho", dnsp.getLocal()); + lua.writeVariable("dh", static_cast(&dnsp.d)); + lua.writeVariable("dnssecOK", dnsp.d_dnssecOk); + lua.writeVariable("tcp", dnsp.d_tcp); + lua.writeVariable("ednsPKTSize", dnsp.d_ednsRawPacketSizeLimit); + if(dnsp.hasEDNSSubnet()) { + lua.writeVariable("ecswho", dnsp.getRealRemote()); + s_lua_record_ctx->bestwho = dnsp.getRealRemote().getNetwork(); + } + else { + lua.writeVariable("ecswho", nullptr); + s_lua_record_ctx->bestwho = dnsp.getInnerRemote(); + } + lua.writeVariable("bestwho", s_lua_record_ctx->bestwho); + + if (g_luaRecordExecLimit > 0) { + lua.executeCode(boost::str(boost::format("debug.sethook(report, '', %d)") % g_luaRecordExecLimit)); + } - try { string actual; if(!code.empty() && code[0]!=';') actual = "return " + code; -- 2.47.3