]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
hashtable.c: Avoid infinite loop in ossl_ht_insert()
authorTomas Mraz <tomas@openssl.org>
Fri, 17 May 2024 11:41:09 +0000 (13:41 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 21 Aug 2024 13:21:25 +0000 (15:21 +0200)
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24504)

crypto/hashtable/hashtable.c

index de5fdbeeca194110e821777444a17397b534ebcb..b47d6938b903c856583b4dc54b20c84c5167bae6 100644 (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);
-
-    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: