summary refs log tree commit diff stats
path: root/tests/unit/test-crypto-hash.c
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2024-10-15 13:26:38 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2024-10-22 11:44:23 +0100
commit164f2be1b513c16dfa65f092f223310992c29828 (patch)
treea5ad988389cd824d2801baabca1adce939d640d8 /tests/unit/test-crypto-hash.c
parentdde538c9a76f328a92c532893e97e18785d57364 (diff)
downloadfocaccia-qemu-164f2be1b513c16dfa65f092f223310992c29828.tar.gz
focaccia-qemu-164f2be1b513c16dfa65f092f223310992c29828.zip
tests: correctly validate result buffer in hash/hmac tests
Validate that the pre-allocated buffer pointer was not overwritten
by the hash/hmac APIs.

Reviewed-by: Dorjoy Chowdhury <dorjoychy111@gmail.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'tests/unit/test-crypto-hash.c')
-rw-r--r--tests/unit/test-crypto-hash.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/unit/test-crypto-hash.c b/tests/unit/test-crypto-hash.c
index e5829ca766..76c4699c15 100644
--- a/tests/unit/test-crypto-hash.c
+++ b/tests/unit/test-crypto-hash.c
@@ -123,7 +123,7 @@ static void test_hash_prealloc(void)
     size_t i;
 
     for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
-        uint8_t *result;
+        uint8_t *result, *origresult;
         size_t resultlen;
         int ret;
         size_t j;
@@ -133,7 +133,7 @@ static void test_hash_prealloc(void)
         }
 
         resultlen = expected_lens[i];
-        result = g_new0(uint8_t, resultlen);
+        origresult = result = g_new0(uint8_t, resultlen);
 
         ret = qcrypto_hash_bytes(i,
                                  INPUT_TEXT,
@@ -142,7 +142,8 @@ static void test_hash_prealloc(void)
                                  &resultlen,
                                  &error_fatal);
         g_assert(ret == 0);
-
+        /* Validate that our pre-allocated pointer was not replaced */
+        g_assert(result == origresult);
         g_assert(resultlen == expected_lens[i]);
         for (j = 0; j < resultlen; j++) {
             g_assert(expected_outputs[i][j * 2] == hex[(result[j] >> 4) & 0xf]);