]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enhance error handling code after calling BIO_new in BaseCryptLib.
authorYe Ting <ting.ye@intel.com>
Wed, 7 Aug 2013 08:11:14 +0000 (08:11 +0000)
committertye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 7 Aug 2013 08:11:14 +0000 (08:11 +0000)
Signed-off-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Long Qin <qin.long@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14528 6f19259b-4bc3-4df7-8a09-765794883524

CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Sign.c
CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c

index 078a960d5848e7084ec7516329da7e1da0508c1b..51e648b736a51c9f41d3a24d67a235b937c8f95b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PEM (Privacy Enhanced Mail) Format Handler Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -109,11 +109,14 @@ RsaGetPrivateKeyFromPem (
   // Read encrypted PEM Data.\r
   //\r
   PemBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (PemBio, PemData, (int) PemSize);\r
   if (PemBio == NULL) {\r
     goto _Exit;\r
   }\r
 \r
+  if (BIO_write (PemBio, PemData, (int) PemSize) <= 0) {\r
+    goto _Exit;\r
+  }\r
+\r
   //\r
   // Retrieve RSA Private Key from encrypted PEM data.\r
   //\r
index 25865910f69b072eb9cafce1e0596ee8add26836..63fe78fc8655514a747db6321b6cb1d8583002d5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PKCS#7 SignedData Sign Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -124,7 +124,13 @@ Pkcs7Sign (
   // Convert the data to be signed to BIO format. \r
   //\r
   DataBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (DataBio, InData, (int) InDataSize);\r
+  if (DataBio == NULL) {\r
+    goto _Exit;\r
+  }\r
+\r
+  if (BIO_write (DataBio, InData, (int) InDataSize) <= 0) {\r
+    goto _Exit;\r
+  }\r
 \r
   //\r
   // Create the PKCS#7 signedData structure.\r
@@ -155,6 +161,7 @@ Pkcs7Sign (
 \r
   Tmp        = P7Data;\r
   P7DataSize = i2d_PKCS7 (Pkcs7, (unsigned char **) &Tmp);\r
+  ASSERT (P7DataSize > 19);\r
 \r
   //\r
   // Strip ContentInfo to content only for signeddata. The data be trimmed off\r
index 471fbbbe25e07f5f6a6112a13a227a002f3172d2..05c3f877430ad67c1ec09f11135b6a33b2747fb0 100644 (file)
@@ -10,7 +10,7 @@
   WrapPkcs7Data(), Pkcs7GetSigners(), Pkcs7Verify() will get UEFI Authenticated\r
   Variable and will do basic check for data structure.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -640,7 +640,13 @@ Pkcs7Verify (
   // in PKCS#7 structure. So ignore NULL checking here.\r
   //\r
   DataBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (DataBio, InData, (int)DataLength);\r
+  if (DataBio == NULL) {\r
+    goto _Exit;\r
+  }\r
+\r
+  if (BIO_write (DataBio, InData, (int) DataLength) <= 0) {\r
+    goto _Exit;\r
+  }\r
 \r
   //\r
   // OpenSSL PKCS7 Verification by default checks for SMIME (email signing) and\r