From 8eff512274deafa130ee94e5755de2113abdb08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 20 May 2015 11:41:36 +0200 Subject: [PATCH] Fix possible signedness issue in time comparison --- library/ssl_ticket.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/library/ssl_ticket.c b/library/ssl_ticket.c index 839e87429..18dcdf7b1 100644 --- a/library/ssl_ticket.c +++ b/library/ssl_ticket.c @@ -387,11 +387,16 @@ int mbedtls_ssl_ticket_parse( void *p_ticket, goto cleanup; #if defined(MBEDTLS_HAVE_TIME) - /* Check if still valid */ - if( ( time( NULL) - session->start ) > ctx->ticket_lifetime ) { - ret = MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED; - goto cleanup; + /* Check for expiration */ + time_t current_time = time( NULL ); + + if( current_time < session->start || + (uint32_t)( current_time - session->start ) > ctx->ticket_lifetime ) + { + ret = MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED; + goto cleanup; + } } #endif