From 480416af9d4acb874d5f60bb725334f71103daf7 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 28 Jun 2018 19:04:07 +0200 Subject: [PATCH] Fix argument validation in asn1_write_10x 1 << bits doesn't work when bits is too large. Found by ASan. --- tests/suites/test_suite_psa_crypto.function | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 0d1a25c82..5f705e3e3 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -46,7 +46,9 @@ static int asn1_write_10x( unsigned char **p, { int ret; int len = bits / 8 + 1; - if( x >= 1 << bits ) + if( bits == 0 ) + return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + if( bits <= 8 && x >= 1 << ( bits - 1 ) ) return( MBEDTLS_ERR_ASN1_INVALID_DATA ); if( *p < start || *p - start < (ssize_t) len ) return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );