From 2afa23acf9466fb8000e2594fd9d2fb1fbb73c39 Mon Sep 17 00:00:00 2001 From: JiashengJiang Date: Mon, 5 May 2025 14:23:38 -0400 Subject: [PATCH] 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) --- test/bio_comp_test.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) { -- 2.47.2