]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Prevent a crash with DynBPF objects in client mode 10095/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 17 Feb 2021 09:38:58 +0000 (10:38 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 17 Feb 2021 09:38:58 +0000 (10:38 +0100)
pdns/dnsdist-lua-bindings.cc
pdns/dnsdist-lua.cc

index 8be20c596503ed0cc1b73e83b09d57a04c8078f8..5f04fd5e8ce17078aceb5631a278d31cef96cbf7 100644 (file)
@@ -448,6 +448,10 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
     });
 
     luaCtx.registerFunction<void(std::shared_ptr<DynBPFFilter>::*)(boost::variant<std::string, std::vector<std::pair<int, std::string>>>)>("excludeRange", [](std::shared_ptr<DynBPFFilter> dbpf, boost::variant<std::string, std::vector<std::pair<int, std::string>>> ranges) {
+      if (!dbpf) {
+        return;
+      }
+
       if (ranges.type() == typeid(std::vector<std::pair<int, std::string>>)) {
         for (const auto& range : *boost::get<std::vector<std::pair<int, std::string>>>(&ranges)) {
           dbpf->excludeRange(Netmask(range.second));
@@ -459,6 +463,10 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
     });
 
     luaCtx.registerFunction<void(std::shared_ptr<DynBPFFilter>::*)(boost::variant<std::string, std::vector<std::pair<int, std::string>>>)>("includeRange", [](std::shared_ptr<DynBPFFilter> dbpf, boost::variant<std::string, std::vector<std::pair<int, std::string>>> ranges) {
+      if (!dbpf) {
+        return;
+      }
+
       if (ranges.type() == typeid(std::vector<std::pair<int, std::string>>)) {
         for (const auto& range : *boost::get<std::vector<std::pair<int, std::string>>>(&ranges)) {
           dbpf->includeRange(Netmask(range.second));
index 070f87b59afe3509d66be6eb54382a12579ec935..7535c66ced2ecd2cce3b9c6923e031964d0aa579 100644 (file)
@@ -1642,6 +1642,9 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     });
 
   luaCtx.writeFunction("addBPFFilterDynBlocks", [](const std::unordered_map<ComboAddress,unsigned int, ComboAddress::addressOnlyHash, ComboAddress::addressOnlyEqual>& m, std::shared_ptr<DynBPFFilter> dynbpf, boost::optional<int> seconds, boost::optional<std::string> msg) {
+      if (!dynbpf) {
+        return;
+      }
       setLuaSideEffect();
       struct timespec until, now;
       clock_gettime(CLOCK_MONOTONIC, &now);