]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
namemap: handle NULL names in name2num lookups
authorNikola Pajkovsky <nikolap@openssl.org>
Fri, 6 Mar 2026 08:49:22 +0000 (09:49 +0100)
committerNeil Horman <nhorman@openssl.org>
Tue, 10 Mar 2026 18:31:40 +0000 (14:31 -0400)
Make ossl_namemap_name2num() return 0 when `name` is NULL, so callers can
use a single lookup path without local NULL guards.

Fixes: aec9e7fe1693 ("Allow core_namemap to limit hashtable key sizes")
Resolves: https://scan5.scan.coverity.com/#/project-view/65138/10222?selectedIssue=1683247
Resolves: https://scan5.scan.coverity.com/#/project-view/65138/10222?selectedIssue=1683248
Resolves: https://scan5.scan.coverity.com/#/project-view/65138/10222?selectedIssue=1683249
Signed-off-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
MergeDate: Tue Mar 10 18:29:00 2026
(Merged from https://github.com/openssl/openssl/pull/30286)

(cherry picked from commit b0ba5c81e43053ae0b8a6cb3559e54b7f6d025d9)

crypto/core_namemap.c
crypto/encode_decode/encoder_meth.c
crypto/evp/evp_fetch.c
crypto/store/store_meth.c

index 157222e21753d2ade5cd6028c0de1130ab0b93ec..ae5f42a7e995d65a68b37e57fab42f342c2b41fd 100644 (file)
@@ -150,7 +150,7 @@ int ossl_namemap_name2num(const OSSL_NAMEMAP *namemap, const char *name)
         namemap = ossl_namemap_stored(NULL);
 #endif
 
-    if (namemap == NULL)
+    if (namemap == NULL || name == NULL)
         return 0;
 
     HT_INIT_RAW_KEY(&key);
index d71df816bea88405f222f4ab342dfb86d0d43097..74ba83fc3dd201cd96d34a1fb1268aaca08865e4 100644 (file)
@@ -364,7 +364,7 @@ inner_ossl_encoder_fetch(struct encoder_data_st *methdata,
         return NULL;
     }
 
-    id = name != NULL ? ossl_namemap_name2num(namemap, name) : 0;
+    id = ossl_namemap_name2num(namemap, name);
 
     /*
      * If we haven't found the name yet, chances are that the algorithm to
index 612e57e6f08c78f502f3f1293280e512657a16ed..24eb48103cc852a30265df9ea8d9222b2c6511f8 100644 (file)
@@ -289,7 +289,7 @@ inner_evp_generic_fetch(struct evp_method_data_st *methdata,
     }
 
     /* If we haven't received a name id yet, try to get one for the name */
-    name_id = name != NULL ? ossl_namemap_name2num(namemap, name) : 0;
+    name_id = ossl_namemap_name2num(namemap, name);
 
     /*
      * If we have a name id, calculate a method id with evp_method_id().
@@ -350,7 +350,7 @@ inner_evp_generic_fetch(struct evp_method_data_st *methdata,
                 name_id = ossl_namemap_name2num(namemap, name);
             if (name_id == 0) {
                 ERR_raise_data(ERR_LIB_EVP, ERR_R_FETCH_FAILED,
-                    "Algorithm %s cannot be found", name);
+                    "Algorithm %s cannot be found", name != NULL ? name : "<null>");
                 free_method(method);
                 method = NULL;
             } else {
index 3b60247f4124752492b23faaf76f7bf92c53de47..04c8a8d5f9efc497f1f2d712b601dedadd901ea7 100644 (file)
@@ -302,7 +302,7 @@ inner_loader_fetch(struct loader_data_st *methdata,
     }
 
     /* If we haven't received a name id yet, try to get one for the name */
-    id = scheme != NULL ? ossl_namemap_name2num(namemap, scheme) : 0;
+    id = ossl_namemap_name2num(namemap, scheme);
 
     /*
      * If we haven't found the name yet, chances are that the algorithm to