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>
This commit is contained in:
Hao Wu 2016-07-01 15:12:40 +08:00
parent d8162f5b32
commit 8824c6144c
1 changed files with 6 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
Diffie-Hellman Wrapper Implementation over OpenSSL. 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 This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 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); RetVal = (BOOLEAN) DH_generate_key (DhContext);
if (RetVal) { if (RetVal) {
Size = BN_num_bytes (Dh->pub_key); 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; *PublicKeySize = Size;
return FALSE; return FALSE;
} }