From nobody Thu May 2 05:30:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1495178832906251.6573914155574; Fri, 19 May 2017 00:27:12 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8F35321A16EFF; Fri, 19 May 2017 00:27:11 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 CB38B21A16EEF for ; Fri, 19 May 2017 00:27:09 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 19 May 2017 00:27:09 -0700 Received: from shwde6388.ccr.corp.intel.com ([10.239.9.17]) by FMSMGA003.fm.intel.com with ESMTP; 19 May 2017 00:27:08 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,363,1491289200"; d="scan'208";a="858956936" From: Long Qin To: ting.ye@intel.com, hao.a.wu@intel.com, edk2-devel@lists.01.org Date: Fri, 19 May 2017 15:26:38 +0800 Message-Id: <20170519072638.10232-1-qin.long@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 Subject: [edk2] [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: , Cc: Qin Long MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add more NULL pointer checks before using them in DhGenerateKey and Pkcs7GetCertificatesList functions to eliminate possible dereferenced pointer issue. Cc: Ting Ye Cc: Hao Wu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qin Long Reviewed-by: Hao Wu Reviewed-by: Ye Ting =20 --- 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); --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel