From 12a37b2ae19b1edabf390c0744ae0af9bb9d2b9a Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Thu, 3 Nov 2016 17:29:01 +0000 Subject: 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 Acked-by: Laszlo Ersek Reviewed-by: Liming Gao --- 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 2a0a038..9dd0b45 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 2a0a038..9dd0b45 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 2a0a038..9dd0b45 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 2a0a038..9dd0b45 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 2a0a038..9dd0b45 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 2a0a038..9dd0b45 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 5adddbb..a3aa7d1 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 5adddbb..a3aa7d1 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); } -- cgit v1.1