From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 B236121A16EFD for ; Fri, 19 May 2017 01:39:43 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 May 2017 01:39:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,363,1491289200"; d="scan'208";a="970640741" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga003.jf.intel.com with ESMTP; 19 May 2017 01:39:37 -0700 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 19 May 2017 01:39:37 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 19 May 2017 01:39:36 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.117]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.224]) with mapi id 14.03.0319.002; Fri, 19 May 2017 16:39:33 +0800 From: "Ye, Ting" To: "Long, Qin" , "Wu, Hao A" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] CryptoPkg/BaseCryptLib: Add NULL pointer checks in DH and P7Verify Thread-Index: AQHS0HFZUAClVj5qhE6yFPqXVAIAoqH7Ve0g Date: Fri, 19 May 2017 08:39:32 +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 08:39:43 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ye Ting =20 -----Original Message----- From: Long, Qin=20 Sent: Friday, May 19, 2017 3:27 PM To: Ye, Ting ; Wu, Hao A ; edk2-deve= l@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 Pkcs7Ge= tCertificatesList functions to eliminate possible dereferenced pointer issu= e. 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(-) diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c b/CryptoPkg/Librar= y/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/CryptoP= kg/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