-
Notifications
You must be signed in to change notification settings - Fork 97
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
Check for zero length and NULL buffer pointer. #222
Conversation
Should this have a ChangeLog entry, like Mbed-TLS/mbedtls@e5c9e79 ? |
Nevermind, this is to Mbed Crypto which doesn't have a Changelog. Misread it as going to Mbed TLS. |
Will merge at same time as Mbed-TLS/mbedtls#2793 and Mbed-TLS/mbedtls#2794 |
Surely if |
library/platform_util.c
Outdated
@@ -72,7 +72,8 @@ static void * (* const volatile memset_func)( void *, int, size_t ) = memset; | |||
|
|||
void mbedtls_platform_zeroize( void *buf, size_t len ) | |||
{ | |||
memset_func( buf, 0, len ); | |||
if ( buf != NULL && len > 0 ) |
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.
Given the discussion in #239 (comment), we should probably change this check to just if ( len > 0 )
and avoid the NULL check. This will allow static analyzers to see that buf
is not allowed to be NULL for this function (and, as a very small bonus, we can save a tiny amount of code space).
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.
PSA and mbedtls APIs work differently here. In PSA Crypto, a null pointer dereference is supposed to invoke the platform's equivalent of a segmentation fault. In mbedtls, in low-level modules, a null pointer dereference is supposed to invoke MBEDTLS_PARAM_FAILED
if MBEDTLS_CHECK_PARAMS
is enabled (and segfaults otherwise), and many high-level modules (e.g. md, cipher and pk) return an error code on null pointers.
Here, I think the correct behavior is
MBEDTLS_INTERNAL_VALIDATE( len == 0 || buf != NULL );
if( len > 0 )
memset_func( buf, 0, len );
0fc1dfe
to
2224f39
Compare
Forced push to accommodate reviewer change request. |
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 remove trailing whitespace from the commit that added it, so that no trailing whitespace is ever added in the git log.
library/platform_util.c
Outdated
memset_func( buf, 0, len ); | ||
MBEDTLS_INTERNAL_VALIDATE( len == 0 || buf != NULL ); | ||
|
||
if ( len > 0 ) |
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.
Style:
if ( len > 0 ) | |
if( len > 0 ) |
In reference to issue ARMmbed#49
2224f39
to
52fa174
Compare
Forced push to correct style and trailing whitespaces. |
In reference to issue #49
Backport to 2.16: Mbed-TLS/mbedtls#2793
After analysis this turned out not to be applicable to 2.7.