Merge branch 'iotssl-1368-unsafe-bounds-check-psk-identity-merge-1.3' into mbedtls-1.3-restricted
diff --git a/ChangeLog b/ChangeLog
index af9fdd0..3dfc1c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,8 @@
Security Initiative, Qualcomm Technologies Inc.
* Fix buffer overflow in RSA-PSS verification when the unmasked
data is all zeros.
+ * Fix unsafe bounds check in ssl_parse_client_psk_identity() when adding
+ 64kB to the address of the SSL buffer wraps around.
Bugfix
* Fix memory leak in ssl_set_hostname() when called multiple times.
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 0f0369a..90995c0 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -3141,7 +3141,7 @@
/*
* Receive client pre-shared key identity name
*/
- if( *p + 2 > end )
+ if( end - *p < 2 )
{
SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
@@ -3150,7 +3150,7 @@
n = ( (*p)[0] << 8 ) | (*p)[1];
*p += 2;
- if( n < 1 || n > 65535 || *p + n > end )
+ if( n < 1 || n > 65535 || n > (size_t) ( end - *p ) )
{
SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );