From c5064c83a1d7a65c387b1a09e806e3694df680d3 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Mon, 11 Mar 2024 17:02:03 +0000 Subject: [PATCH] Do not attempt to wipe output buffer if it is NULL If the output buffer is NULL, it either: * Does not need wiping because it is zero-length. * Has failed allocation of a copy. * Has not yet been written to as a copy hasn't been allocated. In any of these circumstances, we should not try to write the buffer, so perform a NULL check before wiping it. Signed-off-by: David Horstmann --- library/psa_crypto.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 9574cd71d1..7473aef4de 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -3658,8 +3658,10 @@ psa_status_t psa_sign_hash_complete( exit: - psa_wipe_tag_output_buffer(signature, status, signature_size, - *signature_length); + if (signature != NULL) { + psa_wipe_tag_output_buffer(signature, status, signature_size, + *signature_length); + } if (status != PSA_OPERATION_INCOMPLETE) { if (status != PSA_SUCCESS) {