-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport 2.7: Fix unsafe bounds check in ssl_load_session() #2132
Backport 2.7: Fix unsafe bounds check in ssl_load_session() #2132
Conversation
a0b64df
to
5e0360a
Compare
@AndrzejKurek Please re-review. |
library/ssl_ticket.c
Outdated
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); | ||
|
||
memcpy( session, p, sizeof( mbedtls_ssl_session ) ); | ||
p += sizeof( mbedtls_ssl_session ); | ||
|
||
#if defined(MBEDTLS_X509_CRT_PARSE_C) | ||
if( p + 3 > end ) | ||
if( 3 > end - p ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing (size_t)
library/ssl_ticket.c
Outdated
@@ -219,14 +219,17 @@ static int ssl_load_session( mbedtls_ssl_session *session, | |||
size_t cert_len; | |||
#endif /* MBEDTLS_X509_CRT_PARSE_C */ | |||
|
|||
if( p + sizeof( mbedtls_ssl_session ) > end ) | |||
if( end < p ) | |||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not in the original PR - is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments.
Use `( x >> y ) & z` instead of `x >> y & z`. Both are equivalent by operator precedence, but the former is more readable and the commonly used idiom in the library.
Fixes Mbed-TLS#659 reported by Guido Vranken.
5e0360a
to
7cf2857
Compare
@AndrzejKurek I was waiting for approval for the main PR before adapting the backports - sorry for not mentioning that. Please re-review. |
Backport reworked in line with the changes in the main PR.
Summary: This is the backport to Mbed TLS 2.7 of #2131 fixing #659.
Internal Reference: IOTSSL-1046.