From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com [IPv6:2a00:1450:400c:c09::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7A26B81D65 for ; Fri, 4 Nov 2016 02:04:43 -0700 (PDT) Received: by mail-wm0-x231.google.com with SMTP id p190so36773677wmp.1 for ; Fri, 04 Nov 2016 02:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=T1hajxTExzm8XXASLHo4NEksBFIhGuEok8d1CeDgTNk=; b=Q5FLvSaHuwj1XpxPosAkJ6phfGFZI0X78chK204eCxgQ8zulCXWgWJMq5Zx3E9t5yx lTp/DqpDRe5pTggkh3BEsQrsk1Xehl6hQjFMXpJHyN5WA0TLkxK62E6CaJJ4WjqNx4P7 jYPdPoIOsC2A7vyQLjR3atYViTilW+r0iS5vg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=T1hajxTExzm8XXASLHo4NEksBFIhGuEok8d1CeDgTNk=; b=BYCAXkbQguGyYFwFmHt5OfzisyjFgzYwnqWsDk9ocUqxudF5mvbS75eOxw1EUFFDbT B/CMnfFWGv6neG1LA1y4AADbkaJRbHq7KlvWwINfnS5GQJsXC6bjeV46HwDOhVlusbBT O2rpTfr3+H/zfm9zmZmoCbS3yu23Oat4tsuQitYHu/sZ0rhMJwM8iW0u6ZgDpqyfIeP4 ohaC5g0r0sfDQhWmk4w+0Zjt0uIO7PRAZMxus9rBA6Mj8/BXI+ZjnQEQQoPU59RyHyEC SsPfmlrVpJff/Njnuef9beH7zxl0CAqnWvkWKW4kzNIzCm6NpjBSqgMm/s1cu2leS886 0XPA== X-Gm-Message-State: ABUngvdMUNpPl/ScygdorRG4Sm1QFQGuyGUJfsrfHBoTle/lnV6Xz8Kf3SNR27rNZRqEj5NS X-Received: by 10.194.95.131 with SMTP id dk3mr7284710wjb.207.1478250283726; Fri, 04 Nov 2016 02:04:43 -0700 (PDT) Received: from localhost.localdomain ([105.151.153.127]) by smtp.gmail.com with ESMTPSA id ba10sm6043913wjb.32.2016.11.04.02.04.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Nov 2016 02:04:43 -0700 (PDT) From: Ard Biesheuvel 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 Date: Fri, 4 Nov 2016 09:04:38 +0000 Message-Id: <1478250278-27796-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [PATCH v3] MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Nov 2016 09:04:43 -0000 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 --- 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