From 660027f3107f3b4babac5fcb9e4b19a7a735d227 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 15 Nov 2023 17:33:47 +0000 Subject: [PATCH] Skip call to memcpy if buffer length is zero This allows the copy functions to work when passed a (NULL, 0) buffer. Signed-off-by: David Horstmann --- library/psa_crypto.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 0cf171699..6b65d6036 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -5543,7 +5543,9 @@ psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len, return PSA_ERROR_CORRUPTION_DETECTED; } - memcpy(input_copy, input, input_len); + if (input_len > 0) { + memcpy(input_copy, input, input_len); + } return PSA_SUCCESS; } @@ -5567,7 +5569,11 @@ psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_co if (output_len < output_copy_len) { return PSA_ERROR_CORRUPTION_DETECTED; } - memcpy(output, output_copy, output_copy_len); + + if (output_copy_len > 0) { + memcpy(output, output_copy, output_copy_len); + } + return PSA_SUCCESS; }