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:58 +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)

(cherry picked from commit 5fbfd641aeebdf4b29a0749e13a79a1e59502878)

crypto/lhash/lhash.c

index c319a44c7b2d715410aa0b9f1606d0b0a876987b..8623bcb395e643383fb06f6bc987fd24d3141707 100644 (file)
@@ -266,12 +266,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--;