From ec6ce03ed9e5504ea001cea6ede2d45c10ad73d6 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 17 Feb 2021 10:38:58 +0100 Subject: [PATCH] dnsdist: Prevent a crash with DynBPF objects in client mode (cherry picked from commit 22189743415af130b0e32a5a13aca1a26f800ead) --- pdns/dnsdist-lua-bindings.cc | 8 ++++++++ pdns/dnsdist-lua.cc | 3 +++ 2 files changed, 11 insertions(+) diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index bc66083f1b..1555f0e250 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -444,6 +444,10 @@ void setupLuaBindings(bool client) }); g_lua.registerFunction::*)(boost::variant>>)>("excludeRange", [](std::shared_ptr dbpf, boost::variant>> ranges) { + if (!dbpf) { + return; + } + if (ranges.type() == typeid(std::vector>)) { for (const auto& range : *boost::get>>(&ranges)) { dbpf->excludeRange(Netmask(range.second)); @@ -455,6 +459,10 @@ void setupLuaBindings(bool client) }); g_lua.registerFunction::*)(boost::variant>>)>("includeRange", [](std::shared_ptr dbpf, boost::variant>> ranges) { + if (!dbpf) { + return; + } + if (ranges.type() == typeid(std::vector>)) { for (const auto& range : *boost::get>>(&ranges)) { dbpf->includeRange(Netmask(range.second)); diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 5de7eb5991..3a66952695 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1559,6 +1559,9 @@ static void setupLuaConfig(bool client, bool configCheck) }); g_lua.writeFunction("addBPFFilterDynBlocks", [](const std::unordered_map& m, std::shared_ptr dynbpf, boost::optional seconds, boost::optional msg) { + if (!dynbpf) { + return; + } setLuaSideEffect(); struct timespec until, now; clock_gettime(CLOCK_MONOTONIC, &now); -- 2.47.2