From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 F2F7D81D65 for ; Fri, 4 Nov 2016 02:09:33 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 04 Nov 2016 02:09:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,442,1473145200"; d="scan'208";a="27710419" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga004.jf.intel.com with ESMTP; 04 Nov 2016 02:09:35 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 4 Nov 2016 02:09:35 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 4 Nov 2016 02:08:30 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.206]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.2]) with mapi id 14.03.0248.002; Fri, 4 Nov 2016 17:08:27 +0800 From: "Gao, Liming" To: Ard Biesheuvel , "edk2-devel@lists.01.org" , "Kinney, Michael D" CC: "Carsey, Jaben" , "lersek@redhat.com" Thread-Topic: [edk2] [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () Thread-Index: AQHSNnqB8+ZURO5/DEinaSjKtjMn7KDIiQag Date: Fri, 4 Nov 2016 09:08:26 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B49ECCA@shsmsx102.ccr.corp.intel.com> References: <1478250278-27796-1-git-send-email-ard.biesheuvel@linaro.org> In-Reply-To: <1478250278-27796-1-git-send-email-ard.biesheuvel@linaro.org> 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 v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () 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: Fri, 04 Nov 2016 09:09:34 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Ard Biesheuvel > Sent: Friday, November 04, 2016 5:05 PM > To: edk2-devel@lists.01.org; Kinney, Michael D > ; Gao, Liming > Cc: Carsey, Jaben ; lersek@redhat.com; Ard > Biesheuvel > Subject: [edk2] [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length > in ZeroMem () >=20 > Unlike other string functions in this library, ZeroMem () does not > return early when the length of the input buffer is 0. So add the > same to ZeroMem () as well, for all implementations of BaseMemoryLib > living under MdePkg/ >=20 > This fixes an issue with the ARM implementation of BaseMemoryLibOPtDxe, > whose InternalMemZeroMem code does not expect a length of 0, and > always > writes at least a single byte. >=20 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ard Biesheuvel > Acked-by: Laszlo Ersek > --- > MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c | 6 +++++- > MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c | 6 +++++- > MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c | 6 +++++- > MdePkg/Library/BaseMemoryLibOptPei/ZeroMemWrapper.c | 6 +++++- > MdePkg/Library/BaseMemoryLibRepStr/ZeroMemWrapper.c | 6 +++++- > MdePkg/Library/BaseMemoryLibSse2/ZeroMemWrapper.c | 6 +++++- > MdePkg/Library/PeiMemoryLib/ZeroMemWrapper.c | 6 +++++- > MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c | 6 +++++- > 8 files changed, 40 insertions(+), 8 deletions(-) >=20 > diff --git a/MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c > b/MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c > index 2a0a038fd6c5..9dd0b45e188e 100644 > --- a/MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c > +++ b/MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > diff --git a/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c > b/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c > index 2a0a038fd6c5..9dd0b45e188e 100644 > --- a/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c > +++ b/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c > b/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c > index 2a0a038fd6c5..9dd0b45e188e 100644 > --- a/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c > +++ b/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > diff --git a/MdePkg/Library/BaseMemoryLibOptPei/ZeroMemWrapper.c > b/MdePkg/Library/BaseMemoryLibOptPei/ZeroMemWrapper.c > index 2a0a038fd6c5..9dd0b45e188e 100644 > --- a/MdePkg/Library/BaseMemoryLibOptPei/ZeroMemWrapper.c > +++ b/MdePkg/Library/BaseMemoryLibOptPei/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > diff --git a/MdePkg/Library/BaseMemoryLibRepStr/ZeroMemWrapper.c > b/MdePkg/Library/BaseMemoryLibRepStr/ZeroMemWrapper.c > index 2a0a038fd6c5..9dd0b45e188e 100644 > --- a/MdePkg/Library/BaseMemoryLibRepStr/ZeroMemWrapper.c > +++ b/MdePkg/Library/BaseMemoryLibRepStr/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > diff --git a/MdePkg/Library/BaseMemoryLibSse2/ZeroMemWrapper.c > b/MdePkg/Library/BaseMemoryLibSse2/ZeroMemWrapper.c > index 2a0a038fd6c5..9dd0b45e188e 100644 > --- a/MdePkg/Library/BaseMemoryLibSse2/ZeroMemWrapper.c > +++ b/MdePkg/Library/BaseMemoryLibSse2/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > diff --git a/MdePkg/Library/PeiMemoryLib/ZeroMemWrapper.c > b/MdePkg/Library/PeiMemoryLib/ZeroMemWrapper.c > index 5adddbbfad66..a3aa7d10a689 100644 > --- a/MdePkg/Library/PeiMemoryLib/ZeroMemWrapper.c > +++ b/MdePkg/Library/PeiMemoryLib/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > diff --git a/MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c > b/MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c > index 5adddbbfad66..a3aa7d10a689 100644 > --- a/MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c > +++ b/MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c > @@ -46,7 +46,11 @@ ZeroMem ( > IN UINTN Length > ) > { > - ASSERT (!(Buffer =3D=3D NULL && Length > 0)); > + if (Length =3D=3D 0) { > + return Buffer; > + } > + > + ASSERT (Buffer !=3D NULL); > ASSERT (Length <=3D (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > -- > 2.7.4 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel