]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg: Fix the dereferenced pointer issue
authorQin Long <qin.long@intel.com>
Tue, 30 Jun 2015 03:27:23 +0000 (03:27 +0000)
committerqlong <qlong@Edk2>
Tue, 30 Jun 2015 03:27:23 +0000 (03:27 +0000)
This patch is to fix one dereferenced pointer issue in new
Pkcs7GetAttachedContent API, and add the memory allocation
failure check.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long <qin.long@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17731 6f19259b-4bc3-4df7-8a09-765794883524

CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c

index b8cfa4286dd509fc644ea6b22b0b89fe9f02838f..d0b0c838b83a4b4ff3a8a4ebeedba9e4d9dcfcd1 100644 (file)
@@ -719,11 +719,6 @@ Pkcs7GetAttachedContent (
   CONST UINT8        *Temp;\r
   ASN1_OCTET_STRING  *OctStr;\r
 \r
   CONST UINT8        *Temp;\r
   ASN1_OCTET_STRING  *OctStr;\r
 \r
-  *Content   = NULL;\r
-  Pkcs7      = NULL;\r
-  SignedData = NULL;\r
-  OctStr     = NULL;\r
-\r
   //\r
   // Check input parameter.\r
   //\r
   //\r
   // Check input parameter.\r
   //\r
@@ -731,6 +726,11 @@ Pkcs7GetAttachedContent (
     return FALSE;\r
   }\r
 \r
     return FALSE;\r
   }\r
 \r
+  *Content   = NULL;\r
+  Pkcs7      = NULL;\r
+  SignedData = NULL;\r
+  OctStr     = NULL;\r
+\r
   Status = WrapPkcs7Data (P7Data, P7Length, &Wrapped, &SignedData, &SignedDataSize);\r
   if (!Status || (SignedDataSize > INT_MAX)) {\r
     goto _Exit;\r
   Status = WrapPkcs7Data (P7Data, P7Length, &Wrapped, &SignedData, &SignedDataSize);\r
   if (!Status || (SignedDataSize > INT_MAX)) {\r
     goto _Exit;\r
@@ -771,6 +771,10 @@ Pkcs7GetAttachedContent (
     if ((OctStr->length > 0) && (OctStr->data != NULL)) {\r
       *ContentSize = OctStr->length;\r
       *Content     = malloc (*ContentSize);\r
     if ((OctStr->length > 0) && (OctStr->data != NULL)) {\r
       *ContentSize = OctStr->length;\r
       *Content     = malloc (*ContentSize);\r
+      if (*Content == NULL) {\r
+        *ContentSize = 0;\r
+        goto _Exit;\r
+      }\r
       CopyMem (*Content, OctStr->data, *ContentSize);\r
     }\r
   }\r
       CopyMem (*Content, OctStr->data, *ContentSize);\r
     }\r
   }\r