coverity 1497107: dereference after null check
authorPauli <ppzgs1@gmail.com>
Thu, 13 Jan 2022 01:30:59 +0000 (12:30 +1100)
committerPauli <pauli@openssl.org>
Fri, 14 Jan 2022 06:06:22 +0000 (17:06 +1100)
Add null checks to avoid dereferencing a pointer that could be null.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/17488)

apps/lib/apps.c

index 7ca30ef590e0558d7fc4d03c89c1f1a5bf12e902..77edc1d9369407383347bd107348f3befdd296f2 100644 (file)
@@ -691,10 +691,13 @@ int load_cert_certs(const char *uri,
     if (ret) {
         if (pcert != NULL)
             warn_cert(uri, *pcert, 0, vpm);
-        warn_certs(uri, *pcerts, 1, vpm);
+        if (pcerts != NULL)
+            warn_certs(uri, *pcerts, 1, vpm);
     } else {
-        OSSL_STACK_OF_X509_free(*pcerts);
-        *pcerts = NULL;
+        if (pcerts != NULL) {
+            OSSL_STACK_OF_X509_free(*pcerts);
+            *pcerts = NULL;
+        }
     }
     return ret;
 }