From: Tomas Mraz Date: Fri, 17 May 2024 11:41:09 +0000 (+0200) Subject: hashtable.c: Avoid infinite loop in ossl_ht_insert() X-Git-Tag: openssl-3.4.0-alpha1~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6cdca7b9febe35d993b6b3e3cd3c276e2387677b;p=thirdparty%2Fopenssl.git hashtable.c: Avoid infinite loop in ossl_ht_insert() Reviewed-by: Neil Horman Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/24504) --- diff --git a/crypto/hashtable/hashtable.c b/crypto/hashtable/hashtable.c index de5fdbeeca1..b47d6938b90 100644 --- a/crypto/hashtable/hashtable.c +++ b/crypto/hashtable/hashtable.c @@ -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); - - if (rc == -1) { - grow_hashtable(h, h->wpd.neighborhood_len); - goto try_again; - } + 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 == 0) + if (rc <= 0) free_value(newval); out: