* [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem ()
@ 2016-11-04 9:04 Ard Biesheuvel
2016-11-04 9:08 ` Gao, Liming
0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2016-11-04 9:04 UTC (permalink / raw)
To: edk2-devel, michael.d.kinney, liming.gao
Cc: lersek, jaben.carsey, 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, for all implementations of BaseMemoryLib
living under MdePkg/
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.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
---
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(-)
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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (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 == NULL && Length > 0));
+ if (Length == 0) {
+ return Buffer;
+ }
+
+ ASSERT (Buffer != NULL);
ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
return InternalMemZeroMem (Buffer, Length);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem ()
2016-11-04 9:04 [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () Ard Biesheuvel
@ 2016-11-04 9:08 ` Gao, Liming
2016-11-04 9:54 ` Ard Biesheuvel
0 siblings, 1 reply; 3+ messages in thread
From: Gao, Liming @ 2016-11-04 9:08 UTC (permalink / raw)
To: Ard Biesheuvel, edk2-devel@lists.01.org, Kinney, Michael D
Cc: Carsey, Jaben, lersek@redhat.com
Reviewed-by: Liming Gao <liming.gao@intel.com>
> -----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
> <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
> Cc: Carsey, Jaben <jaben.carsey@intel.com>; lersek@redhat.com; Ard
> Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: [edk2] [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length
> in ZeroMem ()
>
> 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/
>
> 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.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Acked-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 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(-)
>
> 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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> ASSERT (Length <= (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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> ASSERT (Length <= (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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> ASSERT (Length <= (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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> ASSERT (Length <= (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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> ASSERT (Length <= (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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> ASSERT (Length <= (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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> ASSERT (Length <= (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 == NULL && Length > 0));
> + if (Length == 0) {
> + return Buffer;
> + }
> +
> + ASSERT (Buffer != NULL);
> 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] 3+ messages in thread
* Re: [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem ()
2016-11-04 9:08 ` Gao, Liming
@ 2016-11-04 9:54 ` Ard Biesheuvel
0 siblings, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2016-11-04 9:54 UTC (permalink / raw)
To: Gao, Liming
Cc: edk2-devel@lists.01.org, Kinney, Michael D, Carsey, Jaben,
lersek@redhat.com
On 4 November 2016 at 09:08, Gao, Liming <liming.gao@intel.com> wrote:
> Reviewed-by: Liming Gao <liming.gao@intel.com>
>
Pushed, thanks.
>> -----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
>> <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
>> Cc: Carsey, Jaben <jaben.carsey@intel.com>; lersek@redhat.com; Ard
>> Biesheuvel <ard.biesheuvel@linaro.org>
>> Subject: [edk2] [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length
>> in ZeroMem ()
>>
>> 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/
>>
>> 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.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> Acked-by: Laszlo Ersek <lersek@redhat.com>
>> ---
>> 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(-)
>>
>> 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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> ASSERT (Length <= (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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> ASSERT (Length <= (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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> ASSERT (Length <= (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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> ASSERT (Length <= (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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> ASSERT (Length <= (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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> ASSERT (Length <= (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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> ASSERT (Length <= (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 == NULL && Length > 0));
>> + if (Length == 0) {
>> + return Buffer;
>> + }
>> +
>> + ASSERT (Buffer != NULL);
>> 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] 3+ messages in thread
end of thread, other threads:[~2016-11-04 9:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-04 9:04 [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () Ard Biesheuvel
2016-11-04 9:08 ` Gao, Liming
2016-11-04 9:54 ` Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox