From a68ef953948b504bb192138c77c3fcc639426edb Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Mon, 7 Aug 2023 11:09:51 +0100 Subject: [PATCH] Check length before calling memcmp Signed-off-by: Thomas Daubney --- programs/psa/psa_hash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/psa/psa_hash.c b/programs/psa/psa_hash.c index 86a59f1476..dc698a162a 100644 --- a/programs/psa/psa_hash.c +++ b/programs/psa/psa_hash.c @@ -106,7 +106,7 @@ int main(void) } /* Check the result of the operation against the sample */ - if ((memcmp(hash, sample_hash, sample_hash_len) != 0) || hash_length != sample_hash_len) { + if (hash_length != sample_hash_len || (memcmp(hash, sample_hash, sample_hash_len) != 0)) { mbedtls_printf("Multi-part hash operation gave the wrong result!\n\n"); goto cleanup; } @@ -135,7 +135,7 @@ int main(void) goto cleanup; } - if (memcmp(hash, sample_hash, sample_hash_len) != 0 || hash_length != sample_hash_len) { + if (hash_length != sample_hash_len || (memcmp(hash, sample_hash, sample_hash_len) != 0)) { mbedtls_printf("One-shot hash operation gave the wrong result!\n\n"); goto cleanup; }