Fix coverity issue: CID 1466485 - Explicit NULL dereference in OSSL_STORE_find()
authorShane Lontis <shane.lontis@oracle.com>
Thu, 10 Sep 2020 07:22:40 +0000 (17:22 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Sat, 12 Sep 2020 05:57:23 +0000 (15:57 +1000)
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12847)

crypto/store/store_lib.c
test/ossl_store_test.c

index 98e49d826d4c45e06d41d619f1b3189a20acb07c..8cf051818c25f1f87b1a53f9ce93937563166ea9 100644 (file)
@@ -272,6 +272,10 @@ int OSSL_STORE_find(OSSL_STORE_CTX *ctx, const OSSL_STORE_SEARCH *search)
         ERR_raise(ERR_LIB_OSSL_STORE, OSSL_STORE_R_LOADING_STARTED);
         return 0;
     }
+    if (search == NULL) {
+        ERR_raise(ERR_LIB_OSSL_STORE, ERR_R_PASSED_NULL_PARAMETER);
+        return 0;
+    }
 
     if (ctx->fetched_loader != NULL) {
         OSSL_PARAM_BLD *bld;
index cbae150099eba6835614faa2701f7152faa31a79..9b48827983277da064d8a447fc77c8e6226c189a 100644 (file)
@@ -24,13 +24,18 @@ static int test_store_open(void)
 {
     int ret = 0;
     OSSL_STORE_CTX *sctx = NULL;
+    OSSL_STORE_SEARCH *search = NULL;
     UI_METHOD *ui_method = NULL;
 
-    ret = TEST_ptr(ui_method= UI_create_method("DummyUI"))
+    ret = TEST_ptr(search = OSSL_STORE_SEARCH_by_alias("nothing"))
+          && TEST_ptr(ui_method= UI_create_method("DummyUI"))
           && TEST_ptr(sctx = OSSL_STORE_open_with_libctx(infile, NULL, NULL,
                                                          ui_method, NULL,
-                                                         NULL, NULL));
+                                                         NULL, NULL))
+          && TEST_false(OSSL_STORE_find(sctx, NULL))
+          && TEST_true(OSSL_STORE_find(sctx, search));
     UI_destroy_method(ui_method);
+    OSSL_STORE_SEARCH_free(search);
     OSSL_STORE_close(sctx);
     return ret;
 }