]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Remove assert in core_namemap.c
authorNeil Horman <nhorman@openssl.org>
Sun, 10 Aug 2025 12:25:04 +0000 (08:25 -0400)
committerNeil Horman <nhorman@openssl.org>
Tue, 12 Aug 2025 18:15:50 +0000 (14:15 -0400)
The namemap_add_name function has an assertion to check for the failure
os ossl_ht_insert.

Its there because we assume the operation can't fail since we're under
write lock

But it can fail if we get a malloc failure, as thats what we're testing
for here.

Remove the assert and handle the failure properly.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28216)

crypto/core_namemap.c
crypto/hashtable/hashtable.c

index 51fc4e90e3d4299a8f1a985522da8084e67b53ed..50491db62bbb1d53f33941015e10f85de1ef6269 100644 (file)
@@ -280,11 +280,12 @@ static int namemap_add_name(OSSL_NAMEMAP *namemap, int number,
     HT_SET_KEY_STRING_CASE(&key, name, name);
     val.value = (void *)(intptr_t)number;
     ret = ossl_ht_insert(namemap->namenum_ht, TO_HT_KEY(&key), &val, NULL);
-    if (!ossl_assert(ret != 0)) /* cannot happen as we are under write lock */
-        return 0;
-    if (ret < 1) {
-        /* unable to insert due to too many collisions */
-        ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_TOO_MANY_NAMES);
+    if (ret <= 0) {
+        /*
+         * We either got an allocation failure (INTERNAL_ERROR), or
+         * hit too many conflicts in the table (TOO_MANY_NAMES)
+         */
+        ERR_raise(ERR_LIB_CRYPTO, (ret < 0) ? CRYPTO_R_TOO_MANY_NAMES : ERR_R_INTERNAL_ERROR);
         return 0;
     }
     return number;
index bc0193915721f45039d207e3f9a14e1f6f9a7826..516ac7c822cfc083e32d62143cf840f967684d1b 100644 (file)
@@ -636,6 +636,7 @@ int ossl_ht_insert(HT *h, HT_KEY *key, HT_VALUE *data, HT_VALUE **olddata)
     if (data->value == NULL)
         goto out;
 
+    rc = -1;
     newval = alloc_new_value(h, key, data->value, data->type_id);
     if (newval == NULL)
         goto out;