From bd01350a900fc2c313c8aac314acb6a587b38684 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 15 Sep 2016 10:33:33 +0200 Subject: [PATCH] dnsdist: Gracefully handle invalid addresses in `newServer()` --- pdns/dnsdist-lua.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index fcb8a590ad..337b1da87f 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -219,16 +219,21 @@ vector> setupLua(bool client, const std::string& confi ComboAddress sourceAddr; unsigned int sourceItf = 0; 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 { + ComboAddress address(*addressStr, 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", *addressStr); + return ret; + } ret=std::make_shared(address); } + catch(const PDNSException& e) { + g_outputBuffer="Error creating new server: "+string(e.reason); + errlog("Error creating new server with address %s: %s", addressStr, e.reason); + return ret; + } catch(std::exception& e) { g_outputBuffer="Error creating new server: "+string(e.what()); errlog("Error creating new server with address %s: %s", addressStr, e.what()); @@ -310,15 +315,20 @@ 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 { + 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; + } ret=std::make_shared(address, sourceAddr, sourceItf); } + catch(const PDNSException& e) { + g_outputBuffer="Error creating new server: "+string(e.reason); + errlog("Error creating new server with address %s: %s", boost::get(vars["address"]), e.reason); + return ret; + } catch(std::exception& e) { g_outputBuffer="Error creating new server: "+string(e.what()); errlog("Error creating new server with address %s: %s", boost::get(vars["address"]), e.what()); -- 2.47.2