Fix error handling in lhash contract
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 20 Sep 2023 13:45:56 +0000 (15:45 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 21 Sep 2023 12:50:01 +0000 (14:50 +0200)
When the realloc fails in contract, this not a fatal
error, since the memory is only shrinked. It is also no
option to exit the function at this point, since that
would leave the hash table in an inconsistent state.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22154)

crypto/lhash/lhash.c

index 526af83026064ad379713454072f16aeac332c24..9d2b284ae0fa2777f9b205a1bc32b6728f446b8d 100644 (file)
@@ -260,12 +260,12 @@ static void contract(OPENSSL_LHASH *lh)
         if (n == NULL) {
             /* fputs("realloc error in lhash", stderr); */
             lh->error++;
-            return;
+        } else {
+            lh->b = n;
         }
         lh->num_alloc_nodes /= 2;
         lh->pmax /= 2;
         lh->p = lh->pmax - 1;
-        lh->b = n;
     } else
         lh->p--;