From 10c36c781c0e31a0b8ea8b49167ca79b002eff70 Mon Sep 17 00:00:00 2001 From: itayzafrir Date: Wed, 27 Mar 2019 15:18:45 +0200 Subject: [PATCH] Do not allocate zero sized buffers - rng --- .../crypto/COMPONENT_SPE/psa_crypto_partition.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c b/components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c index fbad1f8fd4..8f907527c9 100644 --- a/components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c +++ b/components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c @@ -1522,10 +1522,14 @@ static void psa_rng_operation(void) case PSA_IPC_CALL: { size_t random_size = msg.out_size[0]; - unsigned char *random = mbedtls_calloc(1, random_size); - if (random == NULL) { - status = PSA_ERROR_INSUFFICIENT_MEMORY; - break; + unsigned char *random = NULL; + + if (random_size > 0) { + random = mbedtls_calloc(1, random_size); + if (random == NULL) { + status = PSA_ERROR_INSUFFICIENT_MEMORY; + break; + } } status = psa_generate_random(random, random_size);