From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: wei6.xu@intel.com) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Thu, 27 Jun 2019 09:26:34 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jun 2019 09:26:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,424,1557212400"; d="scan'208";a="153094516" Received: from shwdeopenpsi174.ccr.corp.intel.com ([10.239.157.39]) by orsmga007.jf.intel.com with ESMTP; 27 Jun 2019 09:26:32 -0700 From: "Xu, Wei6" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Chao B Zhang Subject: [edk2-devel][Patch] MdeModulePkg/DxeCapsuleLibFmp: Add missing NULL pointer check. Date: Fri, 28 Jun 2019 00:26:29 +0800 Message-Id: <20190627162629.16352-1-wei6.xu@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 Add missing NULL pointer check for CapsuleNameBufStart. Also add comments to notice that capsule name integrity check assumes the capsule has been validated by IsValidCapsuleHeader(). Cc: Jian J Wang Cc: Hao A Wu Cc: Chao B Zhang Signed-off-by: Wei6 Xu --- MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c index 66c9be8e1f..3193ca8f4d 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c @@ -23,10 +23,13 @@ IsCapsuleNameCapsule ( /** Check the integrity of the capsule name capsule. If the capsule is vaild, return the physical address of each capsule name string. + This routine assumes the capsule has been validated by IsValidCapsuleHeader(), so + capsule memory overflow is not going to happen in this routine. + @param[in] CapsuleHeader Pointer to the capsule header of a capsule name capsule. @param[out] CapsuleNameNum Number of capsule name. @retval NULL Capsule name capsule is not valid. @retval CapsuleNameBuf Array of capsule name physical address. @@ -63,10 +66,13 @@ ValidateCapsuleNameCapsuleIntegrity ( // // If strings are not aligned on a 16-bit boundary, reallocate memory for it. // if (((UINTN) CapsuleNameBufStart & BIT0) != 0) { CapsuleNameBufStart = AllocateCopyPool (CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize, CapsuleNameBufStart); + if (CapsuleNameBufStart == NULL) { + return NULL; + } } CapsuleNameBufEnd = CapsuleNameBufStart + CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize; CapsuleNamePtr = CapsuleNameBufStart; -- 2.16.2.windows.1