if(pleft>1)
data.hostmaster=attodot(parts[1]); // ahu@ds9a.nl -> ahu.ds9a.nl, piet.puk@ds9a.nl -> piet\.puk.ds9a.nl
- data.serial = pleft > 2 ? strtoul(parts[2].c_str(), NULL, 10) : 0;
+ data.serial = pleft > 2 ? strtoui(parts[2].c_str(), NULL, 10) : 0;
+ if (data.serial == UINT_MAX && errno == ERANGE) throw PDNSException("serial number too large in '"+parts[2]+"'");
data.refresh = pleft > 3 ? atoi(parts[3].c_str())
: ::arg().asNum("soa-refresh-default");
L<<Logger::Error<<"Warning: unable to enable timestamp reporting for socket"<<endl;
#endif
}
+
+uint32_t strtoui(const char *nptr, char **endptr, int base)
+{
+ unsigned long val = strtoul(nptr, endptr, base);
+ if (val > UINT_MAX) {
+ errno = ERANGE;
+ return UINT_MAX;
+ }
+
+ return val;
+}
#include <cstring>
#include <cstdio>
#include <regex.h>
+#include <limits.h>
#include <boost/algorithm/string.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
uint16_t getShort(const char *p);
uint32_t getLong(const unsigned char *p);
uint32_t getLong(const char *p);
+uint32_t strtoui(const char *nptr, char **endptr, int base);
+
int logFacilityToLOG(unsigned int facility);
struct ServiceTuple
throw RecordTextException("expected digits at position "+lexical_cast<string>(d_pos)+" in '"+d_string+"'");
char *endptr;
- unsigned long ret=strtoul(d_string.c_str() + d_pos, &endptr, 10);
+ unsigned long ret=strtoui(d_string.c_str() + d_pos, &endptr, 10);
+ if (ret == UINT_MAX && errno == ERANGE) throw RecordTextException("serial number too large in '"+d_string+"'");
val=ret;
d_pos = endptr - d_string.c_str();
(case_t(QType::AAAA, "23:00::15::43", zone, false)) // double compression
(case_t(QType::AAAA, "2a23:00::15::", zone, false)) // ditto
(case_t(QType::AAAA, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff", zone, false)) // truncated wire value
+ (case_t(QType::SOA, "ns.rec.test hostmaster.test.rec 20130512010 3600 3600 604800 120", zone, false)) // too long serial
;
int n=0;