From f8ad2123f92f53b6988d013fa58619204abfbcc0 Mon Sep 17 00:00:00 2001 From: Steven Cooreman Date: Tue, 11 May 2021 11:09:13 +0200 Subject: [PATCH] Be explicit about why the zero-length check is there Since a valid mac operation context would guarantee that the stored mac size is >= 4, it wasn't immediately obvious that the zero-length check is meant for static analyzers and a bit of robustness. Signed-off-by: Steven Cooreman --- library/psa_crypto.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index b48af39fb..57970dafa 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -2439,8 +2439,12 @@ psa_status_t psa_mac_sign_finish( psa_mac_operation_t *operation, if( ! operation->is_sign ) return( PSA_ERROR_BAD_STATE ); - /* Sanity checks on output buffer length. */ - if( mac_size == 0 || mac_size < operation->mac_size ) + /* Sanity check. This will guarantee that mac_size != 0 (and so mac != NULL) + * once all the error checks are done. */ + if( operation->mac_size == 0 ) + return( PSA_ERROR_BAD_STATE ); + + if( mac_size < operation->mac_size ) return( PSA_ERROR_BUFFER_TOO_SMALL ); status = psa_driver_wrapper_mac_sign_finish( operation,