From: JiashengJiang Date: Mon, 5 May 2025 18:23:38 +0000 (-0400) Subject: test/bio_comp_test.c: Initialize pointer to avoid undefined behavior X-Git-Tag: openssl-3.3.4~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d77ad352d9f9277ce3aea0e5fab5a50ea7095bb2;p=thirdparty%2Fopenssl.git test/bio_comp_test.c: Initialize pointer to avoid undefined behavior If the allocation for "original" fails, "result" may be freed without being properly initialized. Since result could hold a random value due to its assignment in do_bio_comp_test(), freeing it without initialization is unsafe and may lead to undefined behavior. Fixes: 12e96a2360 ("Add brotli compression support (RFC7924)") Signed-off-by: JiashengJiang Reviewed-by: Paul Dale Reviewed-by: Tom Cosgrove Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27569) (cherry picked from commit 4dca928a29cbe413f2416ac5e1ba2fe4e073f608) --- diff --git a/test/bio_comp_test.c b/test/bio_comp_test.c index 75ae46adb6f..9f3bc9b6b1d 100644 --- a/test/bio_comp_test.c +++ b/test/bio_comp_test.c @@ -83,8 +83,10 @@ static int do_bio_comp(const BIO_METHOD *meth, int n) int size = sizes[n % 4]; int type = n / 4; - if (!TEST_ptr(original = OPENSSL_malloc(BUFFER_SIZE)) - || !TEST_ptr(result = OPENSSL_malloc(BUFFER_SIZE))) + original = OPENSSL_malloc(BUFFER_SIZE); + result = OPENSSL_malloc(BUFFER_SIZE); + + if (!TEST_ptr(original) || !TEST_ptr(result)) goto err; switch (type) {