From 5d2e82f0cecf85b347a7d170e55597c58226118c Mon Sep 17 00:00:00 2001 From: Ryan Everett Date: Wed, 7 Feb 2024 17:24:59 +0000 Subject: [PATCH] Guard memcpy so that it won't fail on null input pointer Signed-off-by: Ryan Everett --- library/psa_crypto.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index e8ec3f2058..5ad9f23df8 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -6864,12 +6864,12 @@ static psa_status_t psa_pbkdf2_hmac_set_password(psa_algorithm_t hash_alg, { psa_status_t status = PSA_SUCCESS; if (input_len > PSA_HASH_BLOCK_LENGTH(hash_alg)) { - status = psa_hash_compute(hash_alg, input, input_len, output, - PSA_HMAC_MAX_HASH_BLOCK_SIZE, output_len); - } else { + return psa_hash_compute(hash_alg, input, input_len, output, + PSA_HMAC_MAX_HASH_BLOCK_SIZE, output_len); + } else if (input_len > 0) { memcpy(output, input, input_len); - *output_len = PSA_HASH_BLOCK_LENGTH(hash_alg); } + *output_len = PSA_HASH_BLOCK_LENGTH(hash_alg); return status; } #endif /* MBEDTLS_PSA_BUILTIN_ALG_PBKDF2_HMAC */