Verify that f_send and f_recv send and receive the expected length
Verify that f_send and f_recv send and receive the expected length
Conflicts:
ChangeLog
diff --git a/ChangeLog b/ChangeLog
index 38e536d..f2c54f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,8 +12,9 @@
In the context of SSL, this resulted in handshake failure. #1351
Changes
- * Add guard to validate that out_left can not be negative. Raised by
- samoconnor in #1245.
+ * Verify that when (f_send, f_recv and f_recv_timeout) send or receive
+ more than the required length an error is returned. Raised by
+ Sam O'Connor in #1245.
= mbed TLS 2.1.10 branch released 2018-02-03
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 3f1c406..6ea7094 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -2402,11 +2402,11 @@
if( ret < 0 )
return( ret );
- // At this point ret value is positive, verify that adding ret
- // value to ssl->in_left doesn't cause a wraparound
- if (ssl->in_left + (size_t)ret < ssl->in_left)
+ if ( (size_t)ret > len )
{
- MBEDTLS_SSL_DEBUG_MSG( 1, ( "wraparound happened over in_left value" ) );
+ MBEDTLS_SSL_DEBUG_MSG( 1,
+ ( "f_recv returned %d bytes but only %zu were requested",
+ ret, len ) );
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
}
@@ -2459,7 +2459,9 @@
if( (size_t)ret > ssl->out_left )
{
- MBEDTLS_SSL_DEBUG_MSG( 1, ( "f_send returned value greater than out left size" ) );
+ MBEDTLS_SSL_DEBUG_MSG( 1,
+ ( "f_send returned %d bytes but only %zu bytes were sent",
+ ret, ssl->out_left ) );
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
}