psa_util: convert_der_to_raw_single_int: ensure the input DER integers have valid length

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-02-01 15:25:17 +01:00
parent 3122f4da50
commit 2d73baf171

View file

@ -492,10 +492,10 @@ static int convert_der_to_raw_single_int(unsigned char *der, size_t der_len,
if ((unpadded_len > 0) && (*p == 0x00)) {
p++;
unpadded_len--;
/* It should never happen that the input number is all zeros. */
if (unpadded_len == 0) {
return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
}
}
/* It should never happen that the input number has 0 length. */
if (unpadded_len == 0) {
return MBEDTLS_ERR_ASN1_INVALID_DATA;
}
if (unpadded_len > coordinate_size) {