From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 8158681D40 for ; Thu, 3 Nov 2016 11:31:52 -0700 (PDT) Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED0927F6D0; Thu, 3 Nov 2016 18:31:53 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-178.phx2.redhat.com [10.3.116.178]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA3IVp3A014711; Thu, 3 Nov 2016 14:31:52 -0400 To: Ard Biesheuvel , edk2-devel@ml01.01.org, michael.d.kinney@intel.com, liming.gao@intel.com References: <1478197093-17209-1-git-send-email-ard.biesheuvel@linaro.org> Cc: jaben.carsey@intel.com From: Laszlo Ersek Message-ID: <669d5683-1e32-ce24-356d-9985ff4812ee@redhat.com> Date: Thu, 3 Nov 2016 19:31:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1478197093-17209-1-git-send-email-ard.biesheuvel@linaro.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 03 Nov 2016 18:31:54 +0000 (UTC) Subject: Re: [PATCH v2] MdePkg/BaseMemoryLibOptDxe: 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: Thu, 03 Nov 2016 18:31:52 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 11/03/16 19:18, Ard Biesheuvel wrote: > 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. > > This fixes an issue with the ARM implementation, whose InternalMemZeroMem > code does not expect a length of 0, and always writes at least a single > byte. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ard Biesheuvel > --- > MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > 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 == NULL && Length > 0)); > + if (Length == 0) { > + return Buffer; > + } > + > + ASSERT (Buffer != NULL); > ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1)); > return InternalMemZeroMem (Buffer, Length); > } > Assuming the ARM impl of InternalMemZeroMem() conforms to the InternalMemZeroMem() contract -- if there is such a contract --, I think this patch makes sense: Acked-by: Laszlo Ersek Thanks Laszlo