Fix a possible NULL pointer dereference in create_cert_store()
authorZhou Qingyang <zhou1615@umn.edu>
Wed, 6 Apr 2022 16:48:09 +0000 (00:48 +0800)
committerTomas Mraz <tomas@openssl.org>
Thu, 21 Apr 2022 06:34:34 +0000 (08:34 +0200)
In create_cert_store(), X509_STORE_new() is called and there is a
dereference of it in following function X509_STORE_add_lookup()
without check, which could lead to NULL pointer dereference.

Fix this by adding a NULL check of X509_STORE_new()

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18057)

(cherry picked from commit 3f075967f664aac12951a1d7aa3124d9235cd299)

apps/ts.c

index e65d223348d6d4605b979f0e5e3c0e54f43a8ac0..8d1b0893ad24d6743c5a7f22f04ceb903c94e568 100644 (file)
--- a/apps/ts.c
+++ b/apps/ts.c
@@ -976,6 +976,10 @@ static X509_STORE *create_cert_store(const char *CApath, const char *CAfile,
     const char *propq = app_get0_propq();
 
     cert_ctx = X509_STORE_new();
+    if (cert_ctx == NULL) {
+        BIO_printf(bio_err, "memory allocation failure\n");
+        return NULL;
+    }
     X509_STORE_set_verify_cb(cert_ctx, verify_cb);
     if (CApath != NULL) {
         lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir());