Skip to content

Commit abd9c66

Browse files
author
itayzafrir
committed
Do not allocate zero sized buffers - entropy
1 parent 19b8381 commit abd9c66

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,17 +1467,20 @@ static void psa_entropy_operation(void)
14671467

14681468
case PSA_IPC_CALL: {
14691469
#if (defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_PSA_HAS_ITS_IO))
1470+
unsigned char *seed = NULL;
14701471
uint32_t bytes_read;
14711472
size_t seed_size = msg.in_size[0];
14721473
if (MBEDTLS_ENTROPY_MAX_SEED_SIZE < seed_size) {
14731474
status = PSA_ERROR_INVALID_ARGUMENT;
14741475
break;
14751476
}
14761477

1477-
unsigned char *seed = mbedtls_calloc(1, seed_size);
1478-
if (seed == NULL) {
1479-
status = PSA_ERROR_INSUFFICIENT_MEMORY;
1480-
break;
1478+
if (seed_size > 0) {
1479+
seed = mbedtls_calloc(1, seed_size);
1480+
if (seed == NULL) {
1481+
status = PSA_ERROR_INSUFFICIENT_MEMORY;
1482+
break;
1483+
}
14811484
}
14821485

14831486
bytes_read = psa_read(msg.handle, 0, seed, seed_size);

0 commit comments

Comments
 (0)