From: Neil Horman Date: Sun, 10 Aug 2025 12:25:04 +0000 (-0400) Subject: Remove assert in core_namemap.c X-Git-Tag: openssl-3.6.0-alpha1~183 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0a15d71f6719c5195af9dbd258a52e0b73ed0acd;p=thirdparty%2Fopenssl.git Remove assert in core_namemap.c 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 Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/28216) --- diff --git a/crypto/core_namemap.c b/crypto/core_namemap.c index 51fc4e90e3d..50491db62bb 100644 --- a/crypto/core_namemap.c +++ b/crypto/core_namemap.c @@ -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; diff --git a/crypto/hashtable/hashtable.c b/crypto/hashtable/hashtable.c index bc019391572..516ac7c822c 100644 --- a/crypto/hashtable/hashtable.c +++ b/crypto/hashtable/hashtable.c @@ -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;