summaryrefslogtreecommitdiffstats
path: root/CryptoPkg/Library/BaseCryptLib
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2016-07-01 15:12:40 +0800
committerHao Wu <hao.a.wu@intel.com>2016-07-13 20:40:51 +0800
commit8802897fd884249e849eb67a6ba0cd970021ac7c (patch)
tree318dabbde6c27813e8cea4b4c42e01672a3baeab /CryptoPkg/Library/BaseCryptLib
parent9d4291c8830e24ec993d9b5addd0e119fb4d1774 (diff)
downloadedk2-8802897fd884249e849eb67a6ba0cd970021ac7c.tar.gz
edk2-8802897fd884249e849eb67a6ba0cd970021ac7c.tar.bz2
edk2-8802897fd884249e849eb67a6ba0cd970021ac7c.zip
CryptoPkg BaseCryptLib: Avoid passing NULL ptr to function BN_bn2bin()
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> (cherry picked from commit 8824c6144c73fe4b6355df6dfaee3e80e068c3b1)
Diffstat (limited to 'CryptoPkg/Library/BaseCryptLib')
-rw-r--r--CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
index 9cbf182c70..5e0447b488 100644
--- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
+++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
@@ -1,7 +1,7 @@
/** @file
Diffie-Hellman Wrapper Implementation over OpenSSL.
-Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -246,7 +246,11 @@ DhGenerateKey (
RetVal = (BOOLEAN) DH_generate_key (DhContext);
if (RetVal) {
Size = BN_num_bytes (Dh->pub_key);
- if ((Size > 0) && (*PublicKeySize < (UINTN) Size)) {
+ if (Size <= 0) {
+ *PublicKeySize = 0;
+ return FALSE;
+ }
+ if (*PublicKeySize < (UINTN) Size) {
*PublicKeySize = Size;
return FALSE;
}