Skip to content

Commit 83c9f49

Browse files
author
Hanno Becker
committed
Prevent bounds check bypass through overflow in PSK identity parsing
The check `if( *p + n > end )` in `ssl_parse_client_psk_identity` is unsafe because `*p + n` might overflow, thus bypassing the check. As `n` is a user-specified value up to 65K, this is relevant if the library happens to be located in the last 65K of virtual memory. This commit replaces the check by a safe version.
1 parent 5a1c0e7 commit 83c9f49

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: library/ssl_srv.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3436,7 +3436,7 @@ static int ssl_parse_client_psk_identity( mbedtls_ssl_context *ssl, unsigned cha
34363436
/*
34373437
* Receive client pre-shared key identity name
34383438
*/
3439-
if( *p + 2 > end )
3439+
if( end - *p < 2 )
34403440
{
34413441
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
34423442
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
@@ -3445,7 +3445,7 @@ static int ssl_parse_client_psk_identity( mbedtls_ssl_context *ssl, unsigned cha
34453445
n = ( (*p)[0] << 8 ) | (*p)[1];
34463446
*p += 2;
34473447

3448-
if( n < 1 || n > 65535 || *p + n > end )
3448+
if( n < 1 || n > 65535 || n > (size_t) ( end - *p ) )
34493449
{
34503450
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
34513451
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );

0 commit comments

Comments
 (0)