Merge pull request #3192 from AndrzejKurek/max_pathlen_overflow

Guard from undefined behaviour in case of an INT_MAX max_pathlen
This commit is contained in:
Jaeden Amero 2020-04-16 16:29:44 +01:00 committed by GitHub
commit 31f4cd9de2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 0 deletions

View file

@ -524,6 +524,12 @@ static int x509_get_basic_constraints( unsigned char **p,
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
/* Do not accept max_pathlen equal to INT_MAX to avoid a signed integer
* overflow, which is an undefined behavior. */
if( *max_pathlen == INT_MAX )
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
MBEDTLS_ERR_ASN1_INVALID_LENGTH );
(*max_pathlen)++;
return( 0 );