From 777e74130f409ab69e47d7110c1b81ae0e5d0520 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 e03e2ae122..43495e247e 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -8462,7 +8462,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; } @@ -8486,7 +8488,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; }