Do not allocate zero sized buffers - rng

pull/10232/head
itayzafrir 2019-03-27 15:18:45 +02:00
parent abd9c661ce
commit 749b1e30bb
1 changed files with 8 additions and 4 deletions

View File

@ -1522,11 +1522,15 @@ static void psa_rng_operation(void)
case PSA_IPC_CALL: { case PSA_IPC_CALL: {
size_t random_size = msg.out_size[0]; size_t random_size = msg.out_size[0];
unsigned char *random = mbedtls_calloc(1, random_size); unsigned char *random = NULL;
if (random_size > 0) {
random = mbedtls_calloc(1, random_size);
if (random == NULL) { if (random == NULL) {
status = PSA_ERROR_INSUFFICIENT_MEMORY; status = PSA_ERROR_INSUFFICIENT_MEMORY;
break; break;
} }
}
status = psa_generate_random(random, random_size); status = psa_generate_random(random, random_size);
if (status == PSA_SUCCESS) { if (status == PSA_SUCCESS) {