Fix the checks of X509_LOOKUP_* functions
authorPeiwei Hu <jlu.hpw@foxmail.com>
Tue, 24 May 2022 16:14:35 +0000 (00:14 +0800)
committerTomas Mraz <tomas@openssl.org>
Thu, 23 Jun 2022 10:42:25 +0000 (12:42 +0200)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18400)

apps/lib/apps.c
apps/ts.c
crypto/x509/x509_d2.c

index 16161964b0f639a760cce56c1117f8c46f90e179..53303303b437b03836a9291da91412ad5b5a4229 100644 (file)
@@ -1334,8 +1334,8 @@ X509_STORE *setup_verify(const char *CAfile, int noCAfile,
         if (lookup == NULL)
             goto end;
         if (CAfile != NULL) {
-            if (!X509_LOOKUP_load_file_ex(lookup, CAfile, X509_FILETYPE_PEM,
-                                          libctx, propq)) {
+            if (X509_LOOKUP_load_file_ex(lookup, CAfile, X509_FILETYPE_PEM,
+                                          libctx, propq) <= 0) {
                 BIO_printf(bio_err, "Error loading file %s\n", CAfile);
                 goto end;
             }
@@ -1350,7 +1350,7 @@ X509_STORE *setup_verify(const char *CAfile, int noCAfile,
         if (lookup == NULL)
             goto end;
         if (CApath != NULL) {
-            if (!X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM)) {
+            if (X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM) <= 0) {
                 BIO_printf(bio_err, "Error loading directory %s\n", CApath);
                 goto end;
             }
index 2cebaa8263ab3fecf861dc3263bccdb739777d45..78c3aacced76fd1778c47f5d502c5b1a27a5801c 100644 (file)
--- a/apps/ts.c
+++ b/apps/ts.c
@@ -991,7 +991,7 @@ static X509_STORE *create_cert_store(const char *CApath, const char *CAfile,
             BIO_printf(bio_err, "memory allocation failure\n");
             goto err;
         }
-        if (!X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM)) {
+        if (X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM) <= 0) {
             BIO_printf(bio_err, "Error loading directory %s\n", CApath);
             goto err;
         }
@@ -1003,8 +1003,8 @@ static X509_STORE *create_cert_store(const char *CApath, const char *CAfile,
             BIO_printf(bio_err, "memory allocation failure\n");
             goto err;
         }
-        if (!X509_LOOKUP_load_file_ex(lookup, CAfile, X509_FILETYPE_PEM, libctx,
-                                      propq)) {
+        if (X509_LOOKUP_load_file_ex(lookup, CAfile, X509_FILETYPE_PEM, libctx,
+                                      propq) <= 0) {
             BIO_printf(bio_err, "Error loading file %s\n", CAfile);
             goto err;
         }
@@ -1016,7 +1016,7 @@ static X509_STORE *create_cert_store(const char *CApath, const char *CAfile,
             BIO_printf(bio_err, "memory allocation failure\n");
             goto err;
         }
-        if (!X509_LOOKUP_load_store_ex(lookup, CAstore, libctx, propq)) {
+        if (X509_LOOKUP_load_store_ex(lookup, CAstore, libctx, propq) <= 0) {
             BIO_printf(bio_err, "Error loading store URI %s\n", CAstore);
             goto err;
         }
index 4c2bc4defa3945f6fd0dadb687e449d8a5a8a91d..7838b703d46a17847090bcd22bfbbb21893e447e 100644 (file)
@@ -50,7 +50,7 @@ int X509_STORE_load_file_ex(X509_STORE *ctx, const char *file,
     if (file == NULL
         || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file())) == NULL
         || X509_LOOKUP_load_file_ex(lookup, file, X509_FILETYPE_PEM, libctx,
-                                    propq) == 0)
+                                    propq) <= 0)
         return 0;
 
     return 1;
@@ -67,7 +67,7 @@ int X509_STORE_load_path(X509_STORE *ctx, const char *path)
 
     if (path == NULL
         || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir())) == NULL
-        || X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) == 0)
+        || X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) <= 0)
         return 0;
 
     return 1;