[PATCH] rsaenh: Properly destroy hashes created by CPCreateHash() (Valgrind).

Sven Baars sbaars at codeweavers.com
Sun Feb 13 13:43:46 CST 2022


Signed-off-by: Sven Baars <sbaars at codeweavers.com>
---
Maybe a better way to do this would be to get rid of the HASH_CONTEXT union,
and initialize that handle to NULL in CPCreateHash(). This seems possible
now that everything goes through bcrypt, but maybe there are reasons
to keep the union and the generic impl glue around.

 dlls/rsaenh/implglue.c |  5 +++++
 dlls/rsaenh/rsaenh.c   | 39 ++++++++++++++++++++-------------------
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/dlls/rsaenh/implglue.c b/dlls/rsaenh/implglue.c
index 9d90ad70f53..0104774777d 100644
--- a/dlls/rsaenh/implglue.c
+++ b/dlls/rsaenh/implglue.c
@@ -38,6 +38,8 @@ BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
     BCRYPT_ALG_HANDLE provider;
     NTSTATUS status;
 
+    pHashContext->bcrypt_hash = NULL;
+
     switch (aiAlgid) 
     {
         case CALG_MD2:
@@ -87,6 +89,9 @@ BOOL update_hash_impl(HASH_CONTEXT *pHashContext, const BYTE *pbData, DWORD dwDa
 
 BOOL finalize_hash_impl(HASH_CONTEXT *pHashContext, BYTE *pbHashValue)
 {
+    if (!pHashContext->bcrypt_hash)
+        return TRUE;
+
     BCryptFinishHash(pHashContext->bcrypt_hash, pbHashValue, RSAENH_MAX_HASH_SIZE, 0);
     BCryptDestroyHash(pHashContext->bcrypt_hash);
     return TRUE;
diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c
index a4deb80b0e1..9cac3606a02 100644
--- a/dlls/rsaenh/rsaenh.c
+++ b/dlls/rsaenh/rsaenh.c
@@ -588,25 +588,6 @@ static BOOL copy_hmac_info(PHMAC_INFO *dst, const HMAC_INFO *src) {
     return TRUE;
 }
 
-/******************************************************************************
- * destroy_hash [Internal]
- *
- * Destructor for hash objects
- *
- * PARAMS
- *  pCryptHash [I] Pointer to the hash object to be destroyed. 
- *                 Will be invalid after function returns!
- */
-static void destroy_hash(OBJECTHDR *pObject)
-{
-    CRYPTHASH *pCryptHash = (CRYPTHASH*)pObject;
-        
-    free_hmac_info(pCryptHash->pHMACInfo);
-    free_data_blob(&pCryptHash->tpPRFParams.blobLabel);
-    free_data_blob(&pCryptHash->tpPRFParams.blobSeed);
-    HeapFree(GetProcessHeap(), 0, pCryptHash);
-}
-
 /******************************************************************************
  * init_hash [Internal]
  *
@@ -722,6 +703,26 @@ static inline void finalize_hash(CRYPTHASH *pCryptHash) {
     }
 }
 
+/******************************************************************************
+ * destroy_hash [Internal]
+ *
+ * Destructor for hash objects
+ *
+ * PARAMS
+ *  pCryptHash [I] Pointer to the hash object to be destroyed.
+ *                 Will be invalid after function returns!
+ */
+static void destroy_hash(OBJECTHDR *pObject)
+{
+    CRYPTHASH *pCryptHash = (CRYPTHASH*)pObject;
+
+    finalize_hash(pCryptHash);
+    free_hmac_info(pCryptHash->pHMACInfo);
+    free_data_blob(&pCryptHash->tpPRFParams.blobLabel);
+    free_data_blob(&pCryptHash->tpPRFParams.blobSeed);
+    HeapFree(GetProcessHeap(), 0, pCryptHash);
+}
+
 /******************************************************************************
  * destroy_key [Internal]
  *
-- 
2.30.0.335.ge6362826a0




More information about the wine-devel mailing list