summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-05-09 15:46:20 +0200
committerlouiz’ <louiz@louiz.org>2017-05-09 15:46:20 +0200
commitf7e4adb10bff1c278a8543b230b10881ff3799fa (patch)
tree3b78a631533ad71b2c76f33081bad98fccc79753 /src/network
parentc046d2ea984a3a5e4069604dc4f61c2f9e60ca44 (diff)
downloadbiboumi-f7e4adb10bff1c278a8543b230b10881ff3799fa.tar.gz
biboumi-f7e4adb10bff1c278a8543b230b10881ff3799fa.tar.bz2
biboumi-f7e4adb10bff1c278a8543b230b10881ff3799fa.tar.xz
biboumi-f7e4adb10bff1c278a8543b230b10881ff3799fa.zip
Avoid any potential int overflow
Diffstat (limited to 'src/network')
-rw-r--r--src/network/poller.cpp6
-rw-r--r--src/network/tcp_socket_handler.cpp5
2 files changed, 8 insertions, 3 deletions
diff --git a/src/network/poller.cpp b/src/network/poller.cpp
index ca49180..0f02cc5 100644
--- a/src/network/poller.cpp
+++ b/src/network/poller.cpp
@@ -200,7 +200,11 @@ int Poller::poll(const std::chrono::milliseconds& timeout)
// Unblock all signals, only during the epoll_pwait call
sigset_t empty_signal_set{};
sigemptyset(&empty_signal_set);
- const int nb_events = ::epoll_pwait(this->epfd, revents, max_events, timeout.count(),
+
+ int real_timeout = std::numeric_limits<int>::max();
+ if (timeout.count() < real_timeout) // Just avoid any potential int overflow
+ real_timeout = static_cast<int>(timeout.count());
+ const int nb_events = ::epoll_pwait(this->epfd, revents, max_events, real_timeout,
&empty_signal_set);
if (nb_events == -1)
{
diff --git a/src/network/tcp_socket_handler.cpp b/src/network/tcp_socket_handler.cpp
index 1bd5315..1049375 100644
--- a/src/network/tcp_socket_handler.cpp
+++ b/src/network/tcp_socket_handler.cpp
@@ -227,9 +227,10 @@ void TCPSocketHandler::consume_in_buffer(const std::size_t size)
}
#ifdef BOTAN_FOUND
-void TCPSocketHandler::start_tls(const std::string& address, const std::string& port)
+void TCPSocketHandler::start_tls(const std::string& address, const std::string& port_string)
{
- Botan::TLS::Server_Information server_info(address, "irc", std::stoul(port));
+ auto port = std::min(std::stoul(port_string), static_cast<unsigned long>(std::numeric_limits<uint16_t>::max()));
+ Botan::TLS::Server_Information server_info(address, "irc", static_cast<uint16_t>(port));
auto policy_directory = Config::get("policy_directory", utils::dirname(Config::get_filename()));
if (!policy_directory.empty() && policy_directory[policy_directory.size()-1] != '/')
policy_directory += '/';