diff options
Diffstat (limited to 'Swiften/Client/CoreClient.cpp')
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index 1de1d61..d3711cb 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -1,3 +1,3 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. @@ -87,3 +87,13 @@ void CoreClient::connect(const ClientOptions& o) { std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname; - int proxyPort = o.manualProxyPort == -1 ? systemSOCKS5Proxy.getPort() : o.manualProxyPort; + auto proxyPort = systemSOCKS5Proxy.getPort(); + if (o.manualProxyPort != -1) { + try { + proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort); + } + catch (const boost::numeric::bad_numeric_cast& e) { + SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl; + onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError)); + return; + } + } SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl; @@ -96,3 +106,13 @@ void CoreClient::connect(const ClientOptions& o) { std::string proxyHostname = o.manualProxyHostname.empty() ? systemHTTPConnectProxy.getAddress().toString() : o.manualProxyHostname; - int proxyPort = o.manualProxyPort == -1 ? systemHTTPConnectProxy.getPort() : o.manualProxyPort; + unsigned short proxyPort = systemHTTPConnectProxy.getPort(); + if (o.manualProxyPort != -1) { + try { + proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort); + } + catch (const boost::numeric::bad_numeric_cast& e) { + SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl; + onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError)); + return; + } + } SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl; @@ -110,3 +130,13 @@ void CoreClient::connect(const ClientOptions& o) { std::string host = o.manualHostname.empty() ? jid_.getDomain() : o.manualHostname; - int port = o.manualPort; + unsigned short port = 0; + if (o.manualPort != -1) { + try { + port = boost::numeric_cast<unsigned short>(o.manualPort); + } + catch (const boost::numeric::bad_numeric_cast& e) { + SWIFT_LOG(warning) << "Invalid manual port " << o.manualPort << ": " << e.what() << std::endl; + onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError)); + return; + } + } boost::optional<std::string> serviceLookupPrefix; |