]> granicus.if.org Git - pdns/commitdiff
dnsdist: Gracefully handle invalid addresses in `newServer()`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 15 Sep 2016 08:33:33 +0000 (10:33 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 15 Sep 2016 08:33:33 +0000 (10:33 +0200)
pdns/dnsdist-lua.cc

index fcb8a590ade8a7bd626cccd25183a7f77522edec..337b1da87f48a8b636f8a698dde67f1c1487924b 100644 (file)
@@ -219,16 +219,21 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                        ComboAddress sourceAddr;
                        unsigned int sourceItf = 0;
                        if(auto addressStr = boost::get<string>(&pvars)) {
-                         ComboAddress address(*addressStr, 53);
                          std::shared_ptr<DownstreamState> 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<DownstreamState>(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<std::function<void(void)>> setupLua(bool client, const std::string& confi
                        }
 
                        std::shared_ptr<DownstreamState> ret;
-                       ComboAddress address(boost::get<string>(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<string>(vars["address"]));
-                         return ret;
-                       }
                        try {
+                         ComboAddress address(boost::get<string>(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<string>(vars["address"]));
+                           return ret;
+                         }
                          ret=std::make_shared<DownstreamState>(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<string>(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<string>(vars["address"]), e.what());