]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Widen the try block in luaSynth to catch the lua_report() exception. 16121/head
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 15 Sep 2025 07:18:33 +0000 (09:18 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 15 Sep 2025 10:46:19 +0000 (12:46 +0200)
It may fire if the lua-records-exec-limit value is really, really, really
small.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/lua-record.cc

index cc8c235ec2de9347d2ca0720fd4844adc1842f15..5e7f872da03897dd7a052ada154ba96236d3874e 100644 (file)
@@ -1761,46 +1761,46 @@ static void setupLuaRecords(LuaContext& lua)
 
 std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSZoneRecord& zone_record, const DNSName& zone, const DNSPacket& dnsp, uint16_t qtype, unique_ptr<AuthLua4>& 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<AuthLua4>(::arg()["lua-global-include-dir"]);
-    setupLuaRecords(*LUA->getLua());
-  }
-
   std::vector<shared_ptr<DNSRecordContent>> ret;
 
-  LuaContext& lua = *LUA->getLua();
-
-  s_lua_record_ctx = std::make_unique<lua_record_ctx_t>();
-  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<AuthLua4>(::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<lua_record_ctx_t>();
+    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<const 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);
+
+    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;