Fix of parse_endpoint with invalid port character separator (#757)

This commit is contained in:
Alden Torres 2016-05-27 12:00:54 -04:00 committed by Arvid Norberg
parent d0a870b3dd
commit 10393697cb
3 changed files with 63 additions and 1 deletions

View File

@ -1,5 +1,6 @@
1.1.1 release
* fixed parsing of IPv6 endpoint with invalid port character separator
* fixed dht stats counters that weren't being updated
* make sure add_torrent_alert is always posted before other alerts for
the torrent

View File

@ -105,6 +105,11 @@ namespace libtorrent
}
*port_pos = '\0';
++port_pos;
if (port_pos == str.end() || *port_pos != ':')
{
ec = errors::invalid_port;
return ret;
}
#if TORRENT_USE_IPV6
ret.address(address_v6::from_string(&*start, ec));
#else
@ -125,12 +130,13 @@ namespace libtorrent
if (ec) return ret;
}
++port_pos;
if (port_pos == str.end())
{
ec = errors::invalid_port;
return ret;
}
++port_pos;
ret.port(std::atoi(&*port_pos));
return ret;
}

View File

@ -114,3 +114,58 @@ TORRENT_TEST(socket_io)
TEST_EQUAL(list[0], udp::endpoint(address_v4::from_string("16.5.128.1"), 1337));
}
TORRENT_TEST(parse_invalid_ipv4_endpoint)
{
error_code ec;
tcp::endpoint endp;
endp = parse_endpoint("127.0.0.1-4", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("127.0.0.1", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("127.0.0.1:", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("127.0.0.1X", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("127.0.0.1:4", ec);
TEST_CHECK(!ec);
TEST_EQUAL(endp, ep("127.0.0.1", 4));
ec.clear();
}
#if TORRENT_USE_IPV6
TORRENT_TEST(parse_invalid_ipv6_endpoint)
{
error_code ec;
tcp::endpoint endp;
endp = parse_endpoint("[::1]-4", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("[::1]", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("[::1]:", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("[::1]X", ec);
TEST_CHECK(ec);
ec.clear();
endp = parse_endpoint("[::1]:4", ec);
TEST_CHECK(!ec);
TEST_EQUAL(endp, ep("::1", 4));
ec.clear();
}
#endif