Fix timer issues

- timer not firing when constantly receiving bad messages
- timer not reset on failed reads
- timer incorrectly restarted on resend during read
This commit is contained in:
Manuel Pégourié-Gonnard 2014-10-02 16:51:56 +02:00 committed by Paul Bakker
parent 7a26d73735
commit 4e2f245752

View file

@ -1987,6 +1987,17 @@ int ssl_fetch_input( ssl_context *ssl, size_t nb_want )
return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
}
SSL_DEBUG_MSG( 3, ( "current timer: %u", ssl->time_limit ) );
/*
* Don't even try to read if time's out already.
* This avoids by-passing the timer when repeatedly receiving messages
* that will end up being dropped.
*/
if( ssl_check_timer( ssl ) != 0 )
ret = POLARSSL_ERR_NET_TIMEOUT;
else
{
len = SSL_BUFFER_LEN - ( ssl->in_hdr - ssl->in_buf );
if( ssl->state != SSL_HANDSHAKE_OVER )
@ -1997,7 +2008,8 @@ int ssl_fetch_input( ssl_context *ssl, size_t nb_want )
SSL_DEBUG_MSG( 3, ( "f_recv_timeout: %u ms", timeout ) );
if( ssl->f_recv_timeout != NULL && timeout != 0 )
ret = ssl->f_recv_timeout( ssl->p_bio, ssl->in_hdr, len, timeout );
ret = ssl->f_recv_timeout( ssl->p_bio, ssl->in_hdr, len,
timeout );
else
ret = ssl->f_recv( ssl->p_bio, ssl->in_hdr, len );
@ -2005,12 +2017,12 @@ int ssl_fetch_input( ssl_context *ssl, size_t nb_want )
if( ret == 0 )
return( POLARSSL_ERR_SSL_CONN_EOF );
}
if( ret == POLARSSL_ERR_NET_TIMEOUT ||
( ret == POLARSSL_ERR_NET_WANT_READ &&
ssl_check_timer( ssl ) != 0 ) )
if( ret == POLARSSL_ERR_NET_TIMEOUT )
{
SSL_DEBUG_MSG( 2, ( "recv timeout" ) );
SSL_DEBUG_MSG( 2, ( "timeout" ) );
ssl_set_timer( ssl, 0 );
if( ssl->state != SSL_HANDSHAKE_OVER )
{
@ -2028,8 +2040,6 @@ int ssl_fetch_input( ssl_context *ssl, size_t nb_want )
return( POLARSSL_ERR_NET_WANT_READ );
}
return( POLARSSL_ERR_NET_TIMEOUT );
}
if( ret < 0 )
@ -2259,9 +2269,6 @@ int ssl_resend( ssl_context *ssl )
ssl_swap_epochs( ssl );
ssl->handshake->retransmit_state = SSL_RETRANS_SENDING;
/* Cancel running timer */
ssl_set_timer( ssl, 0 );
}
while( ssl->handshake->cur_msg != NULL )
@ -2296,9 +2303,10 @@ int ssl_resend( ssl_context *ssl )
if( ssl->state == SSL_HANDSHAKE_OVER )
ssl->handshake->retransmit_state = SSL_RETRANS_FINISHED;
else
{
ssl->handshake->retransmit_state = SSL_RETRANS_WAITING;
ssl_set_timer( ssl, ssl->handshake->retransmit_timeout );
}
SSL_DEBUG_MSG( 2, ( "<= ssl_resend" ) );