]> 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>
Tue, 1 May 2018 15:15:38 +0000 (17:15 +0200)
(cherry picked from commit 2f975181d5d660e25cc4cd41f1e30788da56df96)

pdns/misc.cc

index 46434506950421c2192f6e99471887331cfdab7a..16b3908f52adeb0f93fa3290aa6e75a82731655d 100644 (file)
@@ -1306,7 +1306,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");
   }