]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Try to be abit more smart in recognizing IP:port combos for both
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 25 Aug 2020 07:48:15 +0000 (09:48 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 5 Oct 2020 11:16:06 +0000 (13:16 +0200)
IPV4 and IPv6.

Should fix #7743

pdns/reczones.cc

index 87ec45732c1014a4994feb20c861e8eacca4048b..487781b2893f580d6d455a421b0332a415318b08 100644 (file)
@@ -261,20 +261,24 @@ static void makeIPToNamesZone(std::shared_ptr<SyncRes::domainmap_t> newMap, cons
 
 ComboAddress parseIPAndPort(const std::string& input, uint16_t port)
 {
-  if(input.find(':') == string::npos || input.empty()) // common case
+  if (input.find(':') == string::npos || input.empty()) { // common case
     return ComboAddress(input, port);
+  }
 
   pair<string,string> both;
-
   try { // case 2
-    both=splitField(input,':');
-    uint16_t newport=static_cast<uint16_t>(pdns_stou(both.second));
+    string::size_type cpos = input.rfind(':');
+    both.first = input.substr(0, cpos);
+    both.second = input.substr(cpos + 1);
+
+    uint16_t newport = static_cast<uint16_t>(pdns_stou(both.second));
     return ComboAddress(both.first, newport);
-  } 
-  catch(...){}
+  }
+  catch(...) {
+  }
 
-  if(input[0]=='[') { // case 4
-    both=splitField(input.substr(1),']');
+  if (input[0] == '[') { // case 4
+    both = splitField(input.substr(1), ']');
     return ComboAddress(both.first, both.second.empty() ? port : static_cast<uint16_t>(pdns_stou(both.second.substr(1))));
   }