Skip to content

Commit ccde952

Browse files
Merge pull request #259 from k-stachowiak/bounds-check-asn1-len
Check `len` against buffers size upper bound in PSA tests
2 parents 0eaf49c + 9b88efc commit ccde952

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tests/suites/test_suite_psa_crypto.function

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ int asn1_skip_integer( unsigned char **p, const unsigned char *end,
736736
TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len,
737737
MBEDTLS_ASN1_INTEGER ),
738738
0 );
739+
740+
/* Check if the retrieved length doesn't extend the actual buffer's size.
741+
* It is assumed here, that end >= p, which validates casting to size_t. */
742+
TEST_ASSERT( len <= (size_t)( end - *p) );
743+
739744
/* Tolerate a slight departure from DER encoding:
740745
* - 0 may be represented by an empty string or a 1-byte string.
741746
* - The sign bit may be used as a value bit. */

0 commit comments

Comments
 (0)