From: Remi Gacogne Date: Wed, 17 Feb 2021 09:38:58 +0000 (+0100) Subject: dnsdist: Prevent a crash with DynBPF objects in client mode X-Git-Tag: dnsdist-1.5.2~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10162%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Prevent a crash with DynBPF objects in client mode (cherry picked from commit 22189743415af130b0e32a5a13aca1a26f800ead) --- 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);