public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: "edk2-devel@lists.01.org" <edk2-devel@ml01.01.org>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>,
	"Gao, Liming" <liming.gao@intel.com>
Subject: Re: [PATCH] MdePkg/BaseMemoryLibOptDxe: check for zero length in ZeroMem ()
Date: Thu, 3 Nov 2016 19:10:43 +0100	[thread overview]
Message-ID: <7b9acc46-3670-bf1b-7e11-740deb57f5fc@redhat.com> (raw)
In-Reply-To: <CAKv+Gu-80Mk2W7hT013=jGvSFhFsoYivATc19CapWJ=WdZYjeA@mail.gmail.com>

On 11/03/16 19:05, Ard Biesheuvel wrote:
> On 3 November 2016 at 17:38, Laszlo Ersek <lersek@redhat.com> wrote:
>> On 11/03/16 18:31, 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.
>>>
>>> Contributed-under: TianoCore Contribution Agreement 1.0
>>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>>> ---
>>>  MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c | 4 ++++
>>>  1 file changed, 4 insertions(+)
>>>
>>> diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c b/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c
>>> index 2a0a038fd6c5..fbc2f5742c8c 100644
>>> --- a/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c
>>> +++ b/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c
>>> @@ -46,6 +46,10 @@ ZeroMem (
>>>    IN UINTN  Length
>>>    )
>>>  {
>>> +  if (Length == 0) {
>>> +    return Buffer;
>>> +  }
>>> +
>>>    ASSERT (!(Buffer == NULL && Length > 0));
>>>    ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
>>>    return InternalMemZeroMem (Buffer, Length);
>>>
>>
>> 1. Why is this necessary?
>>
> 
> The 32-bit accelerated ARM code writes at least one byte,

Does that conform to the InternalMemZeroMem() contract?

> and given
> that the other string functions take the same shortcut, this seemed
> the most appropriate way to fix that.

I don't disagree, but then the commit message should explain this -- the
circumstances where the missing shortcut actually caused a problem.

> 
>> 2. After the new check, Length is guaranteed to be positive. The first
>> ASSERT() should be updated (simplified), I think:
>>
>>   ASSERT (Buffer != NULL);
>>
> 
> Good point. I will change that
> 

Thanks!
Laszlo


  reply	other threads:[~2016-11-03 18:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03 17:31 [PATCH] MdePkg/BaseMemoryLibOptDxe: check for zero length in ZeroMem () Ard Biesheuvel
2016-11-03 17:38 ` Laszlo Ersek
2016-11-03 18:05   ` Ard Biesheuvel
2016-11-03 18:10     ` Laszlo Ersek [this message]
2016-11-03 17:38 ` Carsey, Jaben

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7b9acc46-3670-bf1b-7e11-740deb57f5fc@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox