diff --git a/src/string_util.cpp b/src/string_util.cpp index b2984aaba..5d53a3baf 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -272,8 +272,15 @@ namespace libtorrent while (start < in.size() && is_digit(in[start]) && in[start] != ',') port += in[start++]; - if (port.empty()) iface.port = -1; - else iface.port = std::atoi(port.c_str()); + if (port.empty() || port.size() > 5) + { + iface.port = -1; + } + else + { + iface.port = std::atoi(port.c_str()); + if (iface.port <= 0 || iface.port > 65535) iface.port = -1; + } // skip spaces while (start < in.size() && is_space(in[start])) diff --git a/test/Jamfile b/test/Jamfile index 04769668b..025eebb05 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -206,6 +206,7 @@ test-suite libtorrent : # transitioned into simulations alias win-tests : test_primitives + test_string test_dht test_sha1_hash test_bitfield