From 4aa5d88fdb616da0102ef869e1c4eeb8f02f9e97 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 1 Apr 2024 11:10:24 +0100 Subject: [PATCH] testsc: fix disorganised alloc/free in test_hash(). These tests also failed when I reran testsc, and looking at the code, no wonder: in each test iteration, the hash object is allocated _before_ logging begins, rather than after, so that its addresses aren't normalised by the test suite to 'n bytes after allocation #0'. So these tests only pass as long as all the allocations get lucky in reusing the same address. I guess we got lucky on all previous occasions and didn't notice until now. Easy fix: now each iteration does alloc / do stuff / free within the logged section. --- test/testsc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/testsc.c b/test/testsc.c index 97d0ce25..00421a67 100644 --- a/test/testsc.c +++ b/test/testsc.c @@ -1567,6 +1567,7 @@ static void test_hash(const ssh_hashalg *halg) test_skipped = true; return; } + ssh_hash_free(h); size_t datalen = 256; uint8_t *data = snewn(datalen, uint8_t); @@ -1576,16 +1577,14 @@ static void test_hash(const ssh_hashalg *halg) random_read(data, datalen); log_start(); + h = ssh_hash_new(halg); put_data(h, data, datalen); ssh_hash_final(h, hash); log_end(); - - h = ssh_hash_new(halg); } sfree(data); sfree(hash); - ssh_hash_free(h); } #define HASH_TESTFN(Y_unused, hash) \