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 D72A081D5B for ; Tue, 8 Nov 2016 21:22:02 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP; 08 Nov 2016 21:22:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,612,1473145200"; d="scan'208";a="899352816" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga003.jf.intel.com with ESMTP; 08 Nov 2016 21:22:05 -0800 Received: from fmsmsx123.amr.corp.intel.com (10.18.125.38) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 8 Nov 2016 21:22:05 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx123.amr.corp.intel.com (10.18.125.38) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 8 Nov 2016 21:22:00 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.206]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.139]) with mapi id 14.03.0248.002; Wed, 9 Nov 2016 13:21:58 +0800 From: "Gao, Liming" To: "Wu, Hao A" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools/PeCoffLib: Check 'RelocDir' before finding the relocation block Thread-Index: AQHSOkjAFDg1J7kXGECPUCvQh2hsHqDQHcjg Date: Wed, 9 Nov 2016 05:21:57 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B4A0D27@shsmsx102.ccr.corp.intel.com> References: <1478668705-5484-1-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1478668705-5484-1-git-send-email-hao.a.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools/PeCoffLib: Check 'RelocDir' before finding the relocation block X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2016 05:22:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Wu, Hao A > Sent: Wednesday, November 09, 2016 1:18 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Gao, Liming ; > Zhu, Yonghong > Subject: [PATCH] BaseTools/PeCoffLib: Check 'RelocDir' before finding the > relocation block >=20 > To match the code logics in MdePkg/Library/BasePeCoffLib, add checks for > 'RelocDir' before finding the relocation block. >=20 > Cc: Liming Gao > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Hao Wu > --- > BaseTools/Source/C/Common/BasePeCoff.c | 46 > ++++++++++++++++++++++------------ > 1 file changed, 30 insertions(+), 16 deletions(-) >=20 > diff --git a/BaseTools/Source/C/Common/BasePeCoff.c > b/BaseTools/Source/C/Common/BasePeCoff.c > index 9adbdfa..692663d 100644 > --- a/BaseTools/Source/C/Common/BasePeCoff.c > +++ b/BaseTools/Source/C/Common/BasePeCoff.c > @@ -645,14 +645,21 @@ Returns: > // > if (OptionHeader.Optional32->NumberOfRvaAndSizes > > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { > RelocDir =3D &OptionHeader.Optional32- > >DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; > - RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDir- > >VirtualAddress); > - RelocBaseEnd =3D PeCoffLoaderImageAddress ( > - ImageContext, > - RelocDir->VirtualAddress + RelocDir->Size - 1 > - ); > - if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || RelocBa= seEnd < > RelocBase) { > - ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; > - return RETURN_LOAD_ERROR; > + if ((RelocDir !=3D NULL) && (RelocDir->Size > 0)) { > + RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDir= - > >VirtualAddress); > + RelocBaseEnd =3D PeCoffLoaderImageAddress ( > + ImageContext, > + RelocDir->VirtualAddress + RelocDir->Size - 1 > + ); > + if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || Reloc= BaseEnd < > RelocBase) { > + ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; > + return RETURN_LOAD_ERROR; > + } > + } else { > + // > + // Set base and end to bypass processing below. > + // > + RelocBase =3D RelocBaseEnd =3D 0; > } > } else { > // > @@ -673,14 +680,21 @@ Returns: > // > if (OptionHeader.Optional64->NumberOfRvaAndSizes > > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { > RelocDir =3D &OptionHeader.Optional64- > >DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; > - RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDir- > >VirtualAddress); > - RelocBaseEnd =3D PeCoffLoaderImageAddress ( > - ImageContext, > - RelocDir->VirtualAddress + RelocDir->Size - 1 > - ); > - if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || RelocBa= seEnd < > RelocBase) { > - ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; > - return RETURN_LOAD_ERROR; > + if ((RelocDir !=3D NULL) && (RelocDir->Size > 0)) { > + RelocBase =3D PeCoffLoaderImageAddress (ImageContext, RelocDir= - > >VirtualAddress); > + RelocBaseEnd =3D PeCoffLoaderImageAddress ( > + ImageContext, > + RelocDir->VirtualAddress + RelocDir->Size - 1 > + ); > + if (RelocBase =3D=3D NULL || RelocBaseEnd =3D=3D NULL || Reloc= BaseEnd < > RelocBase) { > + ImageContext->ImageError =3D IMAGE_ERROR_FAILED_RELOCATION; > + return RETURN_LOAD_ERROR; > + } > + } else { > + // > + // Set base and end to bypass processing below. > + // > + RelocBase =3D RelocBaseEnd =3D 0; > } > } else { > // > -- > 1.9.5.msysgit.0