When the socket timeout has to be adjusted because of a handshake timeout expiring earlier, the user set value is saved and reset afterwards. This patch adds a missing if-clause in dgram_reset_rcv_timeout() to prevent the reset of the socket timeout when no timer is active. Since no adjustment has been done then, no previous socket timeout has been saved and the socket timeout will be always set to 0.
--- crypto/bio/bss_dgram.c 5 Jun 2009 14:46:48 -0000 1.7.2.14 +++ crypto/bio/bss_dgram.c 22 Jul 2009 10:56:00 -0000 @@ -250,17 +380,22 @@ { #if defined(SO_RCVTIMEO) bio_dgram_data *data = (bio_dgram_data *)b->ptr; + + /* Is a timer active? */ + if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) + { #ifdef OPENSSL_SYS_WINDOWS - int timeout = data->socket_timeout.tv_sec * 1000 + - data->socket_timeout.tv_usec / 1000; - if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, - (void*)&timeout, sizeof(timeout)) < 0) - { perror("setsockopt"); } -#else - if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &(data- >socket_timeout), - sizeof(struct timeval)) < 0) - { perror("setsockopt"); } + int timeout = data->socket_timeout.tv_sec * 1000 + + data->socket_timeout.tv_usec / 1000; + if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, + (void*)&timeout, sizeof(timeout)) < 0) + { perror("setsockopt"); } +#else + if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &(data- >socket_timeout), + sizeof(struct timeval)) < 0) + { perror("setsockopt"); } #endif + } #endif }
dtls-socket-timeout-bug.patch
Description: Binary data