if(pos == string::npos || pos + 2 > addr.size() || addr[pos+1]!=':')
return -1;
ourAddr.assign(addr.c_str() + 1, pos-1);
- port = pdns_stou(addr.substr(pos+2));
+ try {
+ port = pdns_stou(addr.substr(pos+2));
+ }
+ catch(std::out_of_range) {
+ return -1;
+ }
}
ret->sin6_scope_id=0;
ret->sin6_family=AF_INET6;
freeaddrinfo(res);
}
+ if(port > 65535)
+ // negative ports are found with the pdns_stou above
+ return -1;
+
if(port >= 0)
ret->sin6_port = htons(port);
char *eptr = (char*)str.c_str() + str.size();
int port = strtol(str.c_str() + pos + 1, &eptr, 10);
+ if (port < 0 || port > 65535)
+ return -1;
+
if(*eptr)
return -1;
BOOST_CHECK(c != e);
BOOST_CHECK(d != e);
BOOST_CHECK(!(a != b));
+
+ // Verify that we don't allow invalid port numbers
+ BOOST_CHECK_THROW(ComboAddress("127.0.0.1:70000"), PDNSException); // Port no. too high
+ BOOST_CHECK_THROW(ComboAddress("127.0.0.1:-6"), PDNSException); // Port no. too low
+ BOOST_CHECK_THROW(ComboAddress("[::1]:70000"), PDNSException); // Port no. too high
+ BOOST_CHECK_THROW(ComboAddress("[::1]:-6"), PDNSException); // Port no. too low
}
BOOST_AUTO_TEST_CASE(test_ComboAddressCompare) {