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.6.0-alpha2~35^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22189743415af130b0e32a5a13aca1a26f800ead;p=thirdparty%2Fpdns.git dnsdist: Prevent a crash with DynBPF objects in client mode --- diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index 8be20c5965..5f04fd5e8c 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -448,6 +448,10 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) }); luaCtx.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)); @@ -459,6 +463,10 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) }); luaCtx.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 070f87b59a..7535c66ced 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1642,6 +1642,9 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) }); luaCtx.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);