summaryrefslogtreecommitdiffstats
path: root/MdePkg
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2016-11-03 17:29:01 +0000
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2016-11-04 09:53:01 +0000
commit12a37b2ae19b1edabf390c0744ae0af9bb9d2b9a (patch)
treebed19eb1d230a86c1dec90b1e58dd402c98ddc51 /MdePkg
parent669b6cc60bf610bbee32e79ed165ca604764c169 (diff)
downloadedk2-12a37b2ae19b1edabf390c0744ae0af9bb9d2b9a.tar.gz
edk2-12a37b2ae19b1edabf390c0744ae0af9bb9d2b9a.tar.bz2
edk2-12a37b2ae19b1edabf390c0744ae0af9bb9d2b9a.zip
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> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c6
-rw-r--r--MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c6
-rw-r--r--MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c6
-rw-r--r--MdePkg/Library/BaseMemoryLibOptPei/ZeroMemWrapper.c6
-rw-r--r--MdePkg/Library/BaseMemoryLibRepStr/ZeroMemWrapper.c6
-rw-r--r--MdePkg/Library/BaseMemoryLibSse2/ZeroMemWrapper.c6
-rw-r--r--MdePkg/Library/PeiMemoryLib/ZeroMemWrapper.c6
-rw-r--r--MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c6
8 files changed, 40 insertions, 8 deletions
diff --git a/MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c b/MdePkg/Library/BaseMemoryLib/ZeroMemWrapper.c
index 2a0a038fd6..9dd0b45e18 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 2a0a038fd6..9dd0b45e18 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 2a0a038fd6..9dd0b45e18 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 2a0a038fd6..9dd0b45e18 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 2a0a038fd6..9dd0b45e18 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 2a0a038fd6..9dd0b45e18 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 5adddbbfad..a3aa7d10a6 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 5adddbbfad..a3aa7d10a6 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);
}