public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg/BaseMemoryLibOptDxe: check for zero length in ZeroMem ()
@ 2016-11-03 17:31 Ard Biesheuvel
  2016-11-03 17:38 ` Laszlo Ersek
  2016-11-03 17:38 ` Carsey, Jaben
  0 siblings, 2 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2016-11-03 17:31 UTC (permalink / raw)
  To: edk2-devel, michael.d.kinney, liming.gao; +Cc: Ard Biesheuvel

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);
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] MdePkg/BaseMemoryLibOptDxe: check for zero length in ZeroMem ()
  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 17:38 ` Carsey, Jaben
  1 sibling, 1 reply; 5+ messages in thread
From: Laszlo Ersek @ 2016-11-03 17:38 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel, michael.d.kinney, liming.gao

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?

2. After the new check, Length is guaranteed to be positive. The first
ASSERT() should be updated (simplified), I think:

  ASSERT (Buffer != NULL);

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MdePkg/BaseMemoryLibOptDxe: check for zero length in ZeroMem ()
  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 17:38 ` Carsey, Jaben
  1 sibling, 0 replies; 5+ messages in thread
From: Carsey, Jaben @ 2016-11-03 17:38 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Kinney, Michael D, Gao, Liming

Is it worth modifying the assert after to no longer check length being garter than 0?

Jaben

> On Nov 3, 2016, at 10:33 AM, Ard Biesheuvel <ard.biesheuvel@linaro.org> 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);
> -- 
> 2.7.4
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MdePkg/BaseMemoryLibOptDxe: check for zero length in ZeroMem ()
  2016-11-03 17:38 ` Laszlo Ersek
@ 2016-11-03 18:05   ` Ard Biesheuvel
  2016-11-03 18:10     ` Laszlo Ersek
  0 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2016-11-03 18:05 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: edk2-devel@lists.01.org, Kinney, Michael D, Gao, Liming

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, and given
that the other string functions take the same shortcut, this seemed
the most appropriate way to fix that.

> 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MdePkg/BaseMemoryLibOptDxe: check for zero length in ZeroMem ()
  2016-11-03 18:05   ` Ard Biesheuvel
@ 2016-11-03 18:10     ` Laszlo Ersek
  0 siblings, 0 replies; 5+ messages in thread
From: Laszlo Ersek @ 2016-11-03 18:10 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Kinney, Michael D, Gao, Liming

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-11-03 18:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-11-03 17:38 ` Carsey, Jaben

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox