Commit 999ab8cb authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

catch invalid addresses. added tests for that.

also improved exception message on bad ports.


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac221b@2467 e5f2f494-b856-4b98-b285-d166d9295462
parent 22d942fa
......@@ -511,11 +511,17 @@ IOServiceImpl::IOServiceImpl(AuthSrv* auth_server, const char* const address,
try {
portnum = boost::lexical_cast<uint16_t>(&port);
} catch (const boost::bad_lexical_cast& ex) {
isc_throw(IOError, "[b10-auth] Invalid port number '" << port << "'");
isc_throw(IOError, "Invalid port number '" << &port << "': " <<
ex.what());
}
if (address != NULL) {
asio::ip::address addr = asio::ip::address::from_string(address);
error_code err;
const ip::address addr = ip::address::from_string(address, err);
if (err) {
isc_throw(IOError, "Invalid IP address '" << address << "': "
<< err.message());
}
if (addr.is_v6() && !use_ipv6) {
isc_throw(FatalError,
......
......@@ -96,6 +96,15 @@ TEST(IOServiceTest, badPort) {
EXPECT_THROW(IOService(NULL, NULL, *"domain", true, false), IOError);
}
TEST(IOServiceTest, badAddress) {
EXPECT_THROW(IOService(NULL, "192.0.2.1.1", *TEST_PORT, true, false),
IOError);
EXPECT_THROW(IOService(NULL, "2001:db8:::1", *TEST_PORT, true, false),
IOError);
EXPECT_THROW(IOService(NULL, "localhost", *TEST_PORT, true, false),
IOError);
}
struct addrinfo*
resolveAddress(const int family, const int sock_type, const int protocol) {
const char* const addr = (family == AF_INET6) ?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment