]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg BaseCryptLib: Avoid passing NULL ptr to function BN_bn2bin()
authorHao Wu <hao.a.wu@intel.com>
Fri, 1 Jul 2016 07:12:40 +0000 (15:12 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 12 Jul 2016 00:53:19 +0000 (08:53 +0800)
This commit modifies the code logic to avoid passing NULL pointer to
function BN_bn2bin().

Cc: Long Qin <qin.long@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Qin Long <qin.long@intel.com>
CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c

index 9cbf182c70f5b292a39ab2b67107208fa0173e26..5e0447b488a3396adaab31076af078fb63f86bae 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Diffie-Hellman Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   Diffie-Hellman Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2016, 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
 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
@@ -246,7 +246,11 @@ DhGenerateKey (
   RetVal = (BOOLEAN) DH_generate_key (DhContext);\r
   if (RetVal) {\r
     Size = BN_num_bytes (Dh->pub_key);\r
   RetVal = (BOOLEAN) DH_generate_key (DhContext);\r
   if (RetVal) {\r
     Size = BN_num_bytes (Dh->pub_key);\r
-    if ((Size > 0) && (*PublicKeySize < (UINTN) Size)) {\r
+    if (Size <= 0) {\r
+      *PublicKeySize = 0;\r
+      return FALSE;\r
+    }\r
+    if (*PublicKeySize < (UINTN) Size) {\r
       *PublicKeySize = Size;\r
       return FALSE;\r
     }\r
       *PublicKeySize = Size;\r
       return FALSE;\r
     }\r