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,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);