Add missing index_index() when reloading OCSP responder
authorViktor Dukhovni <openssl-users@dukhovni.org>
Wed, 18 Apr 2018 23:52:26 +0000 (19:52 -0400)
committerViktor Dukhovni <openssl-users@dukhovni.org>
Thu, 19 Apr 2018 02:29:35 +0000 (22:29 -0400)
Also, future-proof index_index() return codes by requiring success
to return a positive value.

Reviewed-by: Rich Salz <rsalz@openssl.org>
apps/apps.c
apps/ca.c
apps/ocsp.c

index 5a32dc0a02ef0a96199273fb30309c1e9952e3c2..6ae85233ccdc6aefabaed72ab532cf9f39a850d4 100644 (file)
@@ -1597,6 +1597,9 @@ CA_DB *load_index(const char *dbfile, DB_ATTR *db_attr)
     return retdb;
 }
 
+/*
+ * Returns > 0 on success, <= 0 on error
+ */
 int index_index(CA_DB *db)
 {
     if (!TXT_DB_create_index(db->db, DB_serial, NULL,
index d530cf5cd71437eecf6f6ba6ba6df6274839644e..1c053b57025602ecb08a5ac71bfd809fc3397f02 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -498,7 +498,7 @@ end_of_options:
         if (db == NULL)
             goto end;
 
-        if (!index_index(db))
+        if (index_index(db) <= 0)
             goto end;
 
         if (get_certificate_status(ser_status, db) != 1)
@@ -672,7 +672,7 @@ end_of_options:
         BIO_printf(bio_err, "generating index\n");
     }
 
-    if (!index_index(db))
+    if (index_index(db) <= 0)
         goto end;
 
     /*****************************************************************/
index 3c5534af0e9dd22ee98d157fd3861ac92eb12102..83461c7cb5ee6fc3dcd6cbe0448ab2a74edc48d6 100644 (file)
@@ -559,7 +559,7 @@ int ocsp_main(int argc, char **argv)
 
     if (ridx_filename != NULL) {
         rdb = load_index(ridx_filename, NULL);
-        if (rdb == NULL || !index_index(rdb)) {
+        if (rdb == NULL || index_index(rdb) <= 0) {
             ret = 1;
             goto end;
         }
@@ -582,10 +582,11 @@ redo_accept:
         if (index_changed(rdb)) {
             CA_DB *newrdb = load_index(ridx_filename, NULL);
 
-            if (newrdb != NULL) {
+            if (newrdb != NULL && index_index(newrdb) > 0) {
                 free_index(rdb);
                 rdb = newrdb;
             } else {
+                free_index(newrdb);
                 log_message(LOG_ERR, "error reloading updated index: %s",
                             ridx_filename);
             }