Prevent DOS by asserts in TCP tuning (#2492)

* Prevent DOS by asserts in TCP tuning

-Propagates socket option errors from the
tuning functions to the callers.
-Asserts a subset of error conditions during tuning,
excluding external network causes.
-Checks tuning results in 3 call sites and treats
them like failures to connect, accept, etc.

* Fix variable name

* Remove lambda requiring C++11
This commit is contained in:
Jake Cobb
2017-04-04 04:55:26 -04:00
committed by Luca Boccassi
parent 1d58a00992
commit 5d5263ed8a
5 changed files with 123 additions and 47 deletions

View File

@@ -136,6 +136,7 @@ void zmq::tcp_connecter_t::out_event ()
handle_valid = false;
const fd_t fd = connect ();
// Handle the error condition by attempt to reconnect.
if (fd == retired_fd) {
close ();
@@ -143,10 +144,15 @@ void zmq::tcp_connecter_t::out_event ()
return;
}
tune_tcp_socket (fd);
tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt,
options.tcp_keepalive_idle, options.tcp_keepalive_intvl);
tune_tcp_maxrt (fd, options.tcp_maxrt);
int rc = tune_tcp_socket (fd);
rc = rc | tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt,
options.tcp_keepalive_idle, options.tcp_keepalive_intvl);
rc = rc | tune_tcp_maxrt (fd, options.tcp_maxrt);
if (rc != 0) {
close ();
add_reconnect_timer ();
return;
}
// Create the engine object for this connection.
stream_engine_t *engine = new (std::nothrow)