From 31a4309077977c050bf1f23622b4704470acf6bc Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Fri, 11 Aug 2017 23:12:56 +0300 Subject: [PATCH] Catch possible exceptions when parsing IPs. Closes #7249. --- src/base/bittorrent/session.cpp | 42 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 616de4500..683ce9b34 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1262,9 +1262,15 @@ void Session::configurePeerClasses() , libt::address_v4::from_string("255.255.255.255") , 1 << libt::session::global_peer_class_id); #if TORRENT_USE_IPV6 - f.add_rule(libt::address_v6::from_string("::0") - , libt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << libt::session::global_peer_class_id); + // IPv6 may not be available on OS and the parsing + // would result in an exception -> abnormal program termination + // Affects Windows XP + try { + f.add_rule(libt::address_v6::from_string("::0") + , libt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") + , 1 << libt::session::global_peer_class_id); + } + catch(std::exception &) {} #endif if (ignoreLimitsOnLAN()) { // local networks @@ -1286,18 +1292,24 @@ void Session::configurePeerClasses() , libt::address_v4::from_string("127.255.255.255") , 1 << libt::session::local_peer_class_id); #if TORRENT_USE_IPV6 - // link local - f.add_rule(libt::address_v6::from_string("fe80::") - , libt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << libt::session::local_peer_class_id); - // unique local addresses - f.add_rule(libt::address_v6::from_string("fc00::") - , libt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << libt::session::local_peer_class_id); - // loopback - f.add_rule(libt::address_v6::from_string("::1") - , libt::address_v6::from_string("::1") - , 1 << libt::session::local_peer_class_id); + // IPv6 may not be available on OS and the parsing + // would result in an exception -> abnormal program termination + // Affects Windows XP + try { + // link local + f.add_rule(libt::address_v6::from_string("fe80::") + , libt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff") + , 1 << libt::session::local_peer_class_id); + // unique local addresses + f.add_rule(libt::address_v6::from_string("fc00::") + , libt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") + , 1 << libt::session::local_peer_class_id); + // loopback + f.add_rule(libt::address_v6::from_string("::1") + , libt::address_v6::from_string("::1") + , 1 << libt::session::local_peer_class_id); + } + catch(std::exception &) {} #endif } m_nativeSession->set_peer_class_filter(f);