]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
API: improve handling of out of range modified_at value 7488/head
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Fri, 15 Feb 2019 20:46:59 +0000 (21:46 +0100)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Fri, 15 Feb 2019 20:51:23 +0000 (21:51 +0100)
Fixes #6114.

pdns/json.cc
regression-tests.api/test_Zones.py

index 34354655fccead21c9e6aec9664a49a007c1b1a4..b1847d06a31fe527d4b1eb1ea7f9d825878c0b69 100644 (file)
@@ -46,7 +46,11 @@ int intFromJson(const Json container, const std::string& key, const int default_
   if (val.is_number()) {
     return val.int_value();
   } else if (val.is_string()) {
-    return std::stoi(val.string_value());
+    try {
+      return std::stoi(val.string_value());
+    } catch (std::out_of_range&) {
+      throw JsonException("Value for key '" + string(key) + "' is out of range");
+    }
   } else {
     // TODO: check if value really isn't present
     return default_value;
@@ -59,7 +63,11 @@ double doubleFromJson(const Json container, const std::string& key)
   if (val.is_number()) {
     return val.number_value();
   } else if (val.is_string()) {
-    return std::stod(val.string_value());
+    try {
+      return std::stod(val.string_value());
+    } catch (std::out_of_range&) {
+      throw JsonException("Value for key '" + string(key) + "' is out of range");
+    }
   } else {
     throw JsonException("Key '" + string(key) + "' not an Integer or not present");
   }
index 9c72fdc10926e3425f76dfc7684b9766969c8451..07325e9de5d76ee4a766299be38b8d39542a92aa 100644 (file)
@@ -1475,6 +1475,29 @@ $ORIGIN %NAME%
         self.assertNotEquals(serverset['records'], [])
         self.assertEquals(serverset['comments'], [])
 
+    def test_zone_comment_out_of_range_modified_at(self):
+        # Test if comments on an rrset stay intact if the rrset is replaced
+        name, payload, zone = self.create_zone()
+        rrset = {
+            'changetype': 'replace',
+            'name': name,
+            'type': 'NS',
+            'comments': [
+                {
+                    'account': 'test1',
+                    'content': 'oh hi there',
+                    'modified_at': '4294967297'
+                }
+            ]
+        }
+        payload = {'rrsets': [rrset]}
+        r = self.session.patch(
+            self.url("/api/v1/servers/localhost/zones/" + name),
+            data=json.dumps(payload),
+            headers={'content-type': 'application/json'})
+        self.assertEquals(r.status_code, 422)
+        self.assertIn("Value for key 'modified_at' is out of range", r.json()['error'])
+
     def test_zone_comment_stay_intact(self):
         # Test if comments on an rrset stay intact if the rrset is replaced
         name, payload, zone = self.create_zone()