Skip to content

Commit 749b1e3

Browse files
author
itayzafrir
committed
Do not allocate zero sized buffers - rng
1 parent abd9c66 commit 749b1e3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,10 +1522,14 @@ static void psa_rng_operation(void)
15221522

15231523
case PSA_IPC_CALL: {
15241524
size_t random_size = msg.out_size[0];
1525-
unsigned char *random = mbedtls_calloc(1, random_size);
1526-
if (random == NULL) {
1527-
status = PSA_ERROR_INSUFFICIENT_MEMORY;
1528-
break;
1525+
unsigned char *random = NULL;
1526+
1527+
if (random_size > 0) {
1528+
random = mbedtls_calloc(1, random_size);
1529+
if (random == NULL) {
1530+
status = PSA_ERROR_INSUFFICIENT_MEMORY;
1531+
break;
1532+
}
15291533
}
15301534

15311535
status = psa_generate_random(random, random_size);

0 commit comments

Comments
 (0)