mirror of https://github.com/openssl/openssl.git
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:
parent
14efc05314
commit
6cdca7b9fe
|
|
@ -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;
|
struct ht_internal_value_st *newval = NULL;
|
||||||
uint64_t hash;
|
uint64_t hash;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (data->value == NULL)
|
if (data->value == NULL)
|
||||||
goto out;
|
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);
|
hash = h->config.ht_hash_fn(key->keybuf, key->keysize);
|
||||||
|
|
||||||
try_again:
|
for (i = 0;
|
||||||
rc = ossl_ht_insert_locked(h, hash, newval, olddata);
|
(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) {
|
if (rc <= 0)
|
||||||
grow_hashtable(h, h->wpd.neighborhood_len);
|
|
||||||
goto try_again;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc == 0)
|
|
||||||
free_value(newval);
|
free_value(newval);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue