From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-x231.google.com (mail-yw0-x231.google.com [IPv6:2607:f8b0:4002:c05::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 2E3F581D66 for ; Fri, 4 Nov 2016 02:54:56 -0700 (PDT) Received: by mail-yw0-x231.google.com with SMTP id l124so77540266ywb.3 for ; Fri, 04 Nov 2016 02:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QuhDG9jWvAsg/yaW41Pn4lGw26YBLjrloYSuETQXLBU=; b=Kz2pb+lFLy5Ttp46gpYddtA4gwzo9F23h3K39fdZPMK1TtCAD0x4gjMA3tRm1QLzKv JPyL/0bE7ELaj0oWKm09bd6FWG89/DHSS54tWIjVl4VqAlNBmetVDAQZ29kxXH1SJ9au RfpzdkrivTYVhepJTjIu2AGfAyHXym1xL4efU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QuhDG9jWvAsg/yaW41Pn4lGw26YBLjrloYSuETQXLBU=; b=VcJAE6uswXZtcyD6G/HfErbdyjg8fWwQ+2zNHTS9LZcIcu82gOJ/JncHTh1fpVIrli 4rDR3zTnGM9OUZhAh6hwf/sEdyCd1XOpyG/A4xUG9P4vybcorAcMad1XE3bpQOIwQDHp sw0Fn7YxATZGh5yIaMWxak2O5RV9GtMrGeICVJjxR+uGm8oXLnbSGJ2s2aT+lV9pRJVG GerBIehz2QT8ppQLIn/WRfQjwzr8zjgEMcTVMUJTjSDAeS4qbsPgyBsbIXFt84WAikQ+ 5k3Xo1xdry0lQ4h89bg25Wdv150Pn4ZJfjQvmFT2otRz5ERT4YypBtqbZf5hSx9iy3Ik lHDg== X-Gm-Message-State: ABUngvfUlY4n9LLMXrPoxCHzRlwYw/6Ys9Ag61ez4E/UvAUKk7yBj6/R7o2Rgu3jHr08yAe2d4sL3EWVs/+qNSvV X-Received: by 10.36.14.131 with SMTP id 125mr1237942ite.59.1478253297076; Fri, 04 Nov 2016 02:54:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.59.147 with HTTP; Fri, 4 Nov 2016 02:54:56 -0700 (PDT) In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14B49ECCA@shsmsx102.ccr.corp.intel.com> References: <1478250278-27796-1-git-send-email-ard.biesheuvel@linaro.org> <4A89E2EF3DFEDB4C8BFDE51014F606A14B49ECCA@shsmsx102.ccr.corp.intel.com> From: Ard Biesheuvel Date: Fri, 4 Nov 2016 09:54:56 +0000 Message-ID: To: "Gao, Liming" Cc: "edk2-devel@lists.01.org" , "Kinney, Michael D" , "Carsey, Jaben" , "lersek@redhat.com" Subject: Re: [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:54:56 -0000 Content-Type: text/plain; charset=UTF-8 On 4 November 2016 at 09:08, Gao, Liming wrote: > Reviewed-by: Liming Gao > 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 >> ; Gao, Liming >> Cc: Carsey, Jaben ; lersek@redhat.com; Ard >> Biesheuvel >> 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 >> 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 >> >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel