resubmit: [PATCH] crypt32: change salt allocation to handle errors (Coverity 133)

Marcus Meissner marcus at jet.franken.de
Wed May 6 03:34:56 CDT 2009


Hi,

Coverity 133 shows that we need a error handling on failing
memory allocation here.

Ciao, Marcus
---
 dlls/crypt32/protectdata.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/dlls/crypt32/protectdata.c b/dlls/crypt32/protectdata.c
index 401e820..cc05397 100644
--- a/dlls/crypt32/protectdata.c
+++ b/dlls/crypt32/protectdata.c
@@ -606,17 +606,19 @@ BOOL fill_protect_data(struct protect_data_t * pInfo, LPCWSTR szDataDescr,
     pInfo->hash_len=CRYPT32_PROTECTDATA_HASH_LEN;
 
     /* allocate memory to hold a salt */
-    if ((pInfo->salt.pbData=CryptMemAlloc(CRYPT32_PROTECTDATA_SALT_LEN)))
+    pInfo->salt.pbData=CryptMemAlloc(CRYPT32_PROTECTDATA_SALT_LEN);
+    if (!pInfo->salt.pbData) {
+        ERR("could not allocate salt data blob\n");
+        return FALSE;
+    }
+    /* generate random salt */
+    if (!CryptGenRandom(hProv, pInfo->salt.cbData, pInfo->salt.pbData))
     {
-        /* generate random salt */
-        if (!CryptGenRandom(hProv, pInfo->salt.cbData, pInfo->salt.pbData))
-        {
-            ERR("CryptGenRandom\n");
-            free_protect_data(pInfo);
-            return FALSE;
-        }
-        pInfo->salt.cbData=CRYPT32_PROTECTDATA_SALT_LEN;
+        ERR("CryptGenRandom\n");
+        free_protect_data(pInfo);
+        return FALSE;
     }
+    pInfo->salt.cbData=CRYPT32_PROTECTDATA_SALT_LEN;
 
     /* debug: show our salt */
     TRACE_DATA_BLOB(&pInfo->salt);
-- 
1.5.6



More information about the wine-patches mailing list