From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A40DD21A16EEF for ; Fri, 19 May 2017 00:33:48 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 19 May 2017 00:33:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,363,1491289200"; d="scan'208";a="104073514" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga005.fm.intel.com with ESMTP; 19 May 2017 00:33:48 -0700 Received: from fmsmsx123.amr.corp.intel.com (10.18.125.38) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 19 May 2017 00:33:48 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx123.amr.corp.intel.com (10.18.125.38) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 19 May 2017 00:33:47 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.178]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.193]) with mapi id 14.03.0319.002; Fri, 19 May 2017 15:33:44 +0800 From: "Wu, Hao A" To: "Long, Qin" , "Ye, Ting" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify Thread-Index: AQHS0HFZ+e8dLXi1f0m0B76L+6X8a6H7Q4MA Date: Fri, 19 May 2017 07:33:44 +0000 Message-ID: References: <20170519072638.10232-1-qin.long@intel.com> In-Reply-To: <20170519072638.10232-1-qin.long@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 May 2017 07:33:48 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Hao Wu 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 an= d > P7Verify >=20 > Add more NULL pointer checks before using them in DhGenerateKey and > Pkcs7GetCertificatesList functions to eliminate possible dereferenced > pointer issue. >=20 > Cc: Ting Ye > Cc: Hao Wu > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Qin Long > --- > CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c | 4 +++- > CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c | 10 +++++++--- > 2 files changed, 10 insertions(+), 4 deletions(-) >=20 > 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; > } >=20 > - BN_bn2bin (DhPubKey, PublicKey); > + if (PublicKey !=3D NULL) { > + BN_bn2bin (DhPubKey, PublicKey); > + } > *PublicKeySize =3D Size; > } >=20 > 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 =3D X509_STORE_CTX_get0_untrusted (CertCtx); > - (VOID)sk_X509_delete_ptr (CtxUntrusted, Signer); > + if (CtxUntrusted !=3D NULL) { > + (VOID)sk_X509_delete_ptr (CtxUntrusted, Signer); > + } >=20 > // > // Build certificates stack chained from Signer's certificate. > @@ -711,8 +713,10 @@ _Error: > } > sk_X509_free (Signers); >=20 > - X509_STORE_CTX_cleanup (CertCtx); > - X509_STORE_CTX_free (CertCtx); > + if (CertCtx !=3D NULL) { > + X509_STORE_CTX_cleanup (CertCtx); > + X509_STORE_CTX_free (CertCtx); > + } >=20 > if (SingleCert !=3D NULL) { > free (SingleCert); > -- > 2.12.2.windows.2