]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/bio_comp_test.c: Initialize pointer to avoid undefined behavior
authorJiashengJiang <jiasheng@purdue.edu>
Mon, 5 May 2025 18:23:38 +0000 (14:23 -0400)
committerTomas Mraz <tomas@openssl.org>
Thu, 8 May 2025 11:47:01 +0000 (13:47 +0200)
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 <jiasheng@purdue.edu>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27569)

test/bio_comp_test.c

index 75ae46adb6fba30680548c652010fd2e30c1adc5..9f3bc9b6b1df77dc5bc851a4f102bbe505c31e22 100644 (file)
@@ -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) {