hashtable.c: Avoid infinite loop in ossl_ht_insert()

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24504)
This commit is contained in:
Tomas Mraz 2024-05-17 13:41:09 +02:00
parent 14efc05314
commit 6cdca7b9fe

View File

@ -623,6 +623,7 @@ int ossl_ht_insert(HT *h, HT_KEY *key, HT_VALUE *data, HT_VALUE **olddata)
struct ht_internal_value_st *newval = NULL;
uint64_t hash;
int rc = 0;
int i;
if (data->value == NULL)
goto out;
@ -637,15 +638,16 @@ int ossl_ht_insert(HT *h, HT_KEY *key, HT_VALUE *data, HT_VALUE **olddata)
*/
hash = h->config.ht_hash_fn(key->keybuf, key->keysize);
try_again:
rc = ossl_ht_insert_locked(h, hash, newval, olddata);
for (i = 0;
(rc = ossl_ht_insert_locked(h, hash, newval, olddata)) == -1
&& i < 2;
++i)
if (!grow_hashtable(h, h->wpd.neighborhood_len)) {
rc = -1;
break;
}
if (rc == -1) {
grow_hashtable(h, h->wpd.neighborhood_len);
goto try_again;
}
if (rc == 0)
if (rc <= 0)
free_value(newval);
out: