* [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify
@ 2017-05-19 7:26 Long Qin
2017-05-19 7:33 ` Wu, Hao A
2017-05-19 8:39 ` Ye, Ting
0 siblings, 2 replies; 3+ messages in thread
From: Long Qin @ 2017-05-19 7:26 UTC (permalink / raw)
To: ting.ye, hao.a.wu, edk2-devel; +Cc: Qin Long
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>
---
CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c | 4 +++-
CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c | 10 +++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
index f44684f907..391efd5c14 100644
--- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
+++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
@@ -232,7 +232,9 @@ DhGenerateKey (
return FALSE;
}
- BN_bn2bin (DhPubKey, PublicKey);
+ if (PublicKey != NULL) {
+ BN_bn2bin (DhPubKey, PublicKey);
+ }
*PublicKeySize = Size;
}
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
index 45d5df5e11..d564591cb7 100644
--- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
+++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
@@ -558,7 +558,9 @@ Pkcs7GetCertificatesList (
}
}
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.
@@ -711,8 +713,10 @@ _Error:
}
sk_X509_free (Signers);
- X509_STORE_CTX_cleanup (CertCtx);
- X509_STORE_CTX_free (CertCtx);
+ if (CertCtx != NULL) {
+ X509_STORE_CTX_cleanup (CertCtx);
+ X509_STORE_CTX_free (CertCtx);
+ }
if (SingleCert != NULL) {
free (SingleCert);
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify
2017-05-19 7:26 [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify Long Qin
@ 2017-05-19 7:33 ` Wu, Hao A
2017-05-19 8:39 ` Ye, Ting
1 sibling, 0 replies; 3+ messages in thread
From: Wu, Hao A @ 2017-05-19 7:33 UTC (permalink / raw)
To: Long, Qin, Ye, Ting, edk2-devel@lists.01.org
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Best Regards,
Hao Wu
> -----Original Message-----
> From: Long, Qin
> Sent: Friday, May 19, 2017 3:27 PM
> To: Ye, Ting; Wu, Hao A; edk2-devel@lists.01.org
> Cc: Long, Qin
> Subject: [PATCH] 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>
> ---
> CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c | 4 +++-
> CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c | 10 +++++++---
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
> b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
> index f44684f907..391efd5c14 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
> +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
> @@ -232,7 +232,9 @@ DhGenerateKey (
> return FALSE;
> }
>
> - BN_bn2bin (DhPubKey, PublicKey);
> + if (PublicKey != NULL) {
> + BN_bn2bin (DhPubKey, PublicKey);
> + }
> *PublicKeySize = Size;
> }
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> index 45d5df5e11..d564591cb7 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> @@ -558,7 +558,9 @@ Pkcs7GetCertificatesList (
> }
> }
> 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.
> @@ -711,8 +713,10 @@ _Error:
> }
> sk_X509_free (Signers);
>
> - X509_STORE_CTX_cleanup (CertCtx);
> - X509_STORE_CTX_free (CertCtx);
> + if (CertCtx != NULL) {
> + X509_STORE_CTX_cleanup (CertCtx);
> + X509_STORE_CTX_free (CertCtx);
> + }
>
> if (SingleCert != NULL) {
> free (SingleCert);
> --
> 2.12.2.windows.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify
2017-05-19 7:26 [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify Long Qin
2017-05-19 7:33 ` Wu, Hao A
@ 2017-05-19 8:39 ` Ye, Ting
1 sibling, 0 replies; 3+ messages in thread
From: Ye, Ting @ 2017-05-19 8:39 UTC (permalink / raw)
To: Long, Qin, Wu, Hao A, edk2-devel@lists.01.org
Reviewed-by: Ye Ting <ting.ye@intel.com>
-----Original Message-----
From: Long, Qin
Sent: Friday, May 19, 2017 3:27 PM
To: Ye, Ting <ting.ye@intel.com>; Wu, Hao A <hao.a.wu@intel.com>; edk2-devel@lists.01.org
Cc: Long, Qin <qin.long@intel.com>
Subject: [PATCH] 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>
---
CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c | 4 +++-
CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c | 10 +++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
index f44684f907..391efd5c14 100644
--- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
+++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
@@ -232,7 +232,9 @@ DhGenerateKey (
return FALSE;
}
- BN_bn2bin (DhPubKey, PublicKey);
+ if (PublicKey != NULL) {
+ BN_bn2bin (DhPubKey, PublicKey);
+ }
*PublicKeySize = Size;
}
diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
index 45d5df5e11..d564591cb7 100644
--- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
+++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
@@ -558,7 +558,9 @@ Pkcs7GetCertificatesList (
}
}
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.
@@ -711,8 +713,10 @@ _Error:
}
sk_X509_free (Signers);
- X509_STORE_CTX_cleanup (CertCtx);
- X509_STORE_CTX_free (CertCtx);
+ if (CertCtx != NULL) {
+ X509_STORE_CTX_cleanup (CertCtx);
+ X509_STORE_CTX_free (CertCtx);
+ }
if (SingleCert != NULL) {
free (SingleCert);
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-05-19 8:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-19 7:26 [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify Long Qin
2017-05-19 7:33 ` Wu, Hao A
2017-05-19 8:39 ` Ye, Ting
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox