]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Check for NULL cleanup function before using it in encoder_process
authorNeil Horman <nhorman@openssl.org>
Sat, 16 Dec 2023 20:32:48 +0000 (15:32 -0500)
committerNeil Horman <nhorman@openssl.org>
Fri, 16 Feb 2024 13:34:11 +0000 (08:34 -0500)
encoder_process assumes a cleanup function has been set in the currently
in-use encoder during processing, which can lead to segfaults if said
function hasn't been set

Add a NULL check for this condition, returning -1 if it is not set

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23069)

crypto/encode_decode/encoder_lib.c

index 28dae99dc8e869dbc34014faf54337deb6aeba53..945b5ba14884a6a1259c3d25838ccd83fd95e52d 100644 (file)
@@ -59,6 +59,11 @@ int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out)
         return 0;
     }
 
+    if (ctx->cleanup == NULL || ctx->construct == NULL) {
+        ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_INIT_FAIL);
+        return 0;
+    }
+
     return encoder_process(&data) > 0;
 }