From 557d7631d26e51415a3ba5efbe8dff7b058d0508 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 18 Jul 2016 15:00:26 +0200 Subject: [PATCH] dnsdist: Prevent the use of "any" addresses for downstream server Otherwise the corresponding `DownstreamState`'s FD is -1 (needed for 'client' mode) and we loop endlessly on `recvfrom()` returning -1. Reported by Sander Smeenk. --- pdns/dnsdist-lua.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index ebd6e41889..0fc8c57e7e 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -194,14 +194,20 @@ vector> setupLua(bool client, const std::string& confi } ComboAddress sourceAddr; unsigned int sourceItf = 0; - if(auto address = boost::get(&pvars)) { + if(auto addressStr = boost::get(&pvars)) { + ComboAddress address(*addressStr, 53); std::shared_ptr ret; + if(IsAnyAddress(address)) { + g_outputBuffer="Error creating new server: invalid address for a downstream server."; + errlog("Error creating new server: %s is not a valid address for a downstream server", *addressStr); + return ret; + } try { - ret=std::make_shared(ComboAddress(*address, 53)); + ret=std::make_shared(address); } catch(std::exception& e) { g_outputBuffer="Error creating new server: "+string(e.what()); - errlog("Error creating new server with address %s: %s", *address, e.what()); + errlog("Error creating new server with address %s: %s", addressStr, e.what()); return ret; } @@ -280,8 +286,14 @@ vector> setupLua(bool client, const std::string& confi } std::shared_ptr ret; + ComboAddress address(boost::get(vars["address"]), 53); + if(IsAnyAddress(address)) { + g_outputBuffer="Error creating new server: invalid address for a downstream server."; + errlog("Error creating new server: %s is not a valid address for a downstream server", boost::get(vars["address"])); + return ret; + } try { - ret=std::make_shared(ComboAddress(boost::get(vars["address"]), 53), sourceAddr, sourceItf); + ret=std::make_shared(address, sourceAddr, sourceItf); } catch(std::exception& e) { g_outputBuffer="Error creating new server: "+string(e.what()); -- 2.47.2