]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2992] Added errno check to fromStringstreamNumber()
authorKazunori Fujiwara <fujiwara@wide.ad.jp>
Tue, 11 Jun 2013 00:35:08 +0000 (09:35 +0900)
committerKazunori Fujiwara <fujiwara@wide.ad.jp>
Tue, 11 Jun 2013 00:35:08 +0000 (09:35 +0900)
       Now support LONG_MAX, LONG_MIN and floating underflow detection

src/lib/cc/data.cc

index af3602abbbecc3f62e85c343b07f9d48aaaba1ce..b23ae02d5781f97f249faaec5499ad3f6fd1246d 100644 (file)
@@ -24,6 +24,7 @@
 #include <iostream>
 #include <string>
 #include <sstream>
+#include <cerrno>
 
 #include <boost/algorithm/string.hpp> // for iequals
 
@@ -395,22 +396,25 @@ fromStringstreamNumber(std::istream& in, int& pos) {
     double d = 0.0;
     bool is_double = false;
     char* endptr;
+    const char* ptr;
 
     std::string number = numberFromStringstream(in, pos);
 
+    errno = 0;
     i = strtol(number.c_str(), &endptr, 10);
     if (*endptr != '\0') {
-        d = strtod(number.c_str(), &endptr);
+        errno = 0;
+        d = strtod(ptr = number.c_str(), &endptr);
         is_double = true;
-        if (*endptr != '\0') {
+        if (*endptr != '\0' || ptr == endptr) {
             isc_throw(JSONError, std::string("Bad number: ") + number);
         } else {
-            if (d == HUGE_VAL || d == -HUGE_VAL) {
+            if (errno != 0) {
                 isc_throw(JSONError, std::string("Number overflow: ") + number);
             }
         }
     } else {
-        if (i == LONG_MAX || i == LONG_MIN) {
+        if ((i == LONG_MAX || i == LONG_MIN) && errno != 0) {
             isc_throw(JSONError, std::string("Number overflow: ") + number);
         }
     }