From 22189743415af130b0e32a5a13aca1a26f800ead 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 --- 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 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); -- 2.47.2