uint32_t octet=0;
val=0;
char count=0;
-
+ bool last_was_digit = false;
+
for(;;) {
if(d_string.at(d_pos)=='.') {
+ if (!last_was_digit)
+ throw RecordTextException(string("unable to parse IP address, dot without previous digit"));
+ last_was_digit = false;
val<<=8;
val+=octet;
octet=0;
count++;
if(count > 3)
- break;
+ throw RecordTextException(string("unable to parse IP address, too many dots"));
}
else if(isdigit(d_string.at(d_pos))) {
+ last_was_digit = true;
octet*=10;
octet+=d_string.at(d_pos) - '0';
if(octet > 255)
if(d_pos == d_string.length())
break;
}
- if(count<=3) {
- val<<=8;
- val+=octet;
- }
+ if (count != 3)
+ throw RecordTextException(string("unable to parse IP address, not enough dots"));
+ if (!last_was_digit)
+ throw RecordTextException(string("unable to parse IP address, trailing dot"));
+ val<<=8;
+ val+=octet;
val=ntohl(val);
}
cases_t cases = boost::assign::list_of
(case_t(QType::A, "932.521.256.42", zone, false)) // hollywood IP
(case_t(QType::A, "932.521", zone, false)) // truncated hollywood IP
- (case_t(QType::A, "10.0", zone, true)) // truncated IP
+ (case_t(QType::A, "10.0", zone, false)) // truncated IP
(case_t(QType::A, "10.0.0.1.", zone, false)) // trailing dot
+ (case_t(QType::A, "10.0.0.", zone, false)) // trailing dot
+ (case_t(QType::A, ".0.0.1", zone, false)) // empty octet
+ (case_t(QType::A, "10..0.1", zone, false)) // empty octet
(case_t(QType::A, "\xca\xec\x00", wire, false)) // truncated wire value
(case_t(QType::A, "127.0.0.1 evil data", zone, false)) // trailing garbage
(case_t(QType::AAAA, "23:00", zone, false)) // time when this test was written