From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=dandan.bi@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 69C07210D9791 for ; Fri, 18 Jan 2019 00:09:08 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2019 00:09:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,489,1539673200"; d="scan'208";a="115631285" Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga007.fm.intel.com with ESMTP; 18 Jan 2019 00:09:05 -0800 From: Dandan Bi To: edk2-devel@lists.01.org Cc: Michael D Kinney , Liming Gao Date: Fri, 18 Jan 2019 16:08:57 +0800 Message-Id: <20190118080857.5016-1-dandan.bi@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 Subject: [patch] MdePkg/BasePeCoffLib: Correct the address of RelocBaseEnd X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jan 2019 08:09:08 -0000 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1426 When calculating the address of RelocBaseEnd, the RelocBase address is ImageBase + RelocDir->VirtualAddress, the size of RelocDir is RelocDir->Size. So the RelocBaseEnd address is: ImageBase + RelocDir->VirtualAddress + RelocDir->Size - 1 not ImageBase + RelocDir->VirtualAddress + RelocDir->Size This patch is to fix this issue when call PeCoffLoaderImageAddress function to calculate the address of RelocBaseEnd. Cc: Michael D Kinney Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index d9c94b89bd..1bd079ad6a 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -1741,11 +1741,11 @@ PeCoffLoaderRelocateImageForRuntime ( // if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { RelocDir = DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC; RelocBase = (EFI_IMAGE_BASE_RELOCATION *) PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0); RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) PeCoffLoaderImageAddress (&ImageContext, - RelocDir->VirtualAddress + RelocDir->Size, + RelocDir->VirtualAddress + RelocDir->Size - 1, 0 ); } else { // // Cannot find relocations, cannot continue to relocate the image, ASSERT for this invalid image. -- 2.18.0.windows.1