]> granicus.if.org Git - pdns/commitdiff
report unparseable data in stoul invalid_argument exception
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 26 Mar 2018 18:37:50 +0000 (20:37 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 26 Mar 2018 18:47:48 +0000 (20:47 +0200)
pdns/misc.cc

index 78ec742b9b674b2831f66b60270bbc7425e0d8b4..8a6388816b84b13016309116cf519b088a29a6f2 100644 (file)
@@ -1360,7 +1360,13 @@ gid_t strToGID(const string &str)
 unsigned int pdns_stou(const std::string& str, size_t * idx, int base)
 {
   if (str.empty()) return 0; // compatibility
-  unsigned long result = std::stoul(str, idx, base);
+  unsigned long result;
+  try {
+    result = std::stoul(str, idx, base);
+  }
+  catch(std::invalid_argument& e) {
+    throw std::invalid_argument(string(e.what()) + "; (invalid argument during std::stoul); data was \""+str+"\"");
+  }
   if (result > std::numeric_limits<unsigned int>::max()) {
     throw std::out_of_range("stou");
   }