From b251f0ea26b8857ba81cb87835de10f62b0e68cd Mon Sep 17 00:00:00 2001 From: samuel40791765 Date: Fri, 13 Sep 2024 20:36:20 +0000 Subject: [PATCH] add null check --- crypto/pem/pem_pkey.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index 59ce84d916f..6bbbc88c782 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -269,6 +269,11 @@ int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, void *u) { + if (bp == NULL || x == NULL || x->ameth == NULL || + x->ameth->pem_str == NULL) { + OPENSSL_PUT_ERROR(PEM, ERR_R_PASSED_NULL_PARAMETER); + return 0; + } char pem_str[80]; BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", x->ameth->pem_str); return PEM_ASN1_write_bio(i2d_PrivateKey_void, pem_str, bp, x, enc, kstr,