From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org, michael.d.kinney@intel.com,
liming.gao@intel.com
Cc: lersek@redhat.com, jaben.carsey@intel.com,
Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem ()
Date: Fri, 4 Nov 2016 09:04:38 +0000 [thread overview]
Message-ID: <1478250278-27796-1-git-send-email-ard.biesheuvel@linaro.org> (raw)
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
next reply other threads:[~2016-11-04 9:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-04 9:04 Ard Biesheuvel [this message]
2016-11-04 9:08 ` [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () Gao, Liming
2016-11-04 9:54 ` Ard Biesheuvel
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=1478250278-27796-1-git-send-email-ard.biesheuvel@linaro.org \
--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