CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify

Add more NULL pointer checks before using them in DhGenerateKey and
Pkcs7GetCertificatesList functions to eliminate possible dereferenced
pointer issue.

Cc: Ting Ye <ting.ye@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long <qin.long@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Ting Ye <ting.ye@intel.com>
This commit is contained in:
Long Qin 2017-05-19 15:22:10 +08:00
parent 112f4ada2e
commit a9fb7b7803
2 changed files with 10 additions and 4 deletions

View File

@ -232,7 +232,9 @@ DhGenerateKey (
return FALSE; return FALSE;
} }
BN_bn2bin (DhPubKey, PublicKey); if (PublicKey != NULL) {
BN_bn2bin (DhPubKey, PublicKey);
}
*PublicKeySize = Size; *PublicKeySize = Size;
} }

View File

@ -558,7 +558,9 @@ Pkcs7GetCertificatesList (
} }
} }
CtxUntrusted = X509_STORE_CTX_get0_untrusted (CertCtx); CtxUntrusted = X509_STORE_CTX_get0_untrusted (CertCtx);
(VOID)sk_X509_delete_ptr (CtxUntrusted, Signer); if (CtxUntrusted != NULL) {
(VOID)sk_X509_delete_ptr (CtxUntrusted, Signer);
}
// //
// Build certificates stack chained from Signer's certificate. // Build certificates stack chained from Signer's certificate.
@ -711,8 +713,10 @@ _Error:
} }
sk_X509_free (Signers); sk_X509_free (Signers);
X509_STORE_CTX_cleanup (CertCtx); if (CertCtx != NULL) {
X509_STORE_CTX_free (CertCtx); X509_STORE_CTX_cleanup (CertCtx);
X509_STORE_CTX_free (CertCtx);
}
if (SingleCert != NULL) { if (SingleCert != NULL) {
free (SingleCert); free (SingleCert);