]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps/lib/apps.c: Add check for BIO_new()
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Thu, 26 Jun 2025 00:01:35 +0000 (00:01 +0000)
committerTomas Mraz <tomas@openssl.org>
Tue, 1 Jul 2025 17:31:54 +0000 (19:31 +0200)
Add checks for the return value of BIO_new() to guarantee successful
allocation, consistent with other usages.

Fixes: a412b89 ("dup_bio_* and bio_open_* are utility functions and belong in apps.c")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27894)

apps/lib/apps.c

index d4e72307de586adaf554ef72c8f39464f5cf1dae..33047c0011272d72dfbed5df5bae7181c463b4d4 100644 (file)
@@ -3048,18 +3048,30 @@ BIO *dup_bio_out(int format)
     BIO *b = BIO_new_fp(stdout,
                         BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));
     void *prefix = NULL;
+    BIO *btmp;
 
     if (b == NULL)
         return NULL;
 
 #ifdef OPENSSL_SYS_VMS
-    if (FMT_istext(format))
-        b = BIO_push(BIO_new(BIO_f_linebuffer()), b);
+    if (FMT_istext(format)) {
+        btmp = BIO_new(BIO_f_linebuffer());
+        if (btmp == NULL) {
+            BIO_free(b);
+            return NULL;
+        }
+        b = BIO_push(btmp, b);
+    }
 #endif
 
     if (FMT_istext(format)
         && (prefix = getenv("HARNESS_OSSL_PREFIX")) != NULL) {
-        b = BIO_push(BIO_new(BIO_f_prefix()), b);
+        btmp = BIO_new(BIO_f_prefix());
+        if (btmp == NULL) {
+            BIO_free_all(b);
+            return NULL;
+        }
+        b = BIO_push(btmp, b);
         BIO_set_prefix(b, prefix);
     }
 
@@ -3072,8 +3084,15 @@ BIO *dup_bio_err(int format)
                         BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));
 
 #ifdef OPENSSL_SYS_VMS
-    if (b != NULL && FMT_istext(format))
-        b = BIO_push(BIO_new(BIO_f_linebuffer()), b);
+    if (b != NULL && FMT_istext(format)) {
+        BIO *btmp = BIO_new(BIO_f_linebuffer());
+
+        if (btmp == NULL) {
+            BIO_free(b);
+            return NULL;
+        }
+        b = BIO_push(btmp, b);
+    }
 #endif
     return b;
 }