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 <steven.cooreman@silabs.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index b48af39..57970da 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -2439,8 +2439,12 @@
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,