From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-x22c.google.com (mail-yw0-x22c.google.com [IPv6:2607:f8b0:4002:c05::22c]) (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 D63FD81D36 for ; Thu, 3 Nov 2016 11:05:01 -0700 (PDT) Received: by mail-yw0-x22c.google.com with SMTP id t125so58418365ywc.1 for ; Thu, 03 Nov 2016 11:05:03 -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=TLN6k6tvKwHqnSY4hunqThXXTr+Gq8WEERwmeZS4rqw=; b=FDS370PUEi24YoVnFzidywO1ITE7G8ivvZkwc4n03S029wtz5LTeL/dBmyBneI6BLM cwbaMVaBTD05cX27WAhW32R65Uve+yJU2XHURkbYhhpdTUw5ITrlom9sKqVSIdvsu8S5 38BFzFuQHIrH2XP7acxOeRBmUa+JY1Sb32vjI= 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=TLN6k6tvKwHqnSY4hunqThXXTr+Gq8WEERwmeZS4rqw=; b=dqA1SL4wXQSGoTyHhxys9yNKpsggYRWKlHUwLKu9kBeO1LK+1YkJ3gaLxJuP6TFEUH SfnZD2gyPWNFCyXtvBvytr4hOqLSQKQOE8ubF7yhEKBdDLHsi3OsSsSaBNs4yJ95cd8G zoBr9l9cIQZytA2Amxz6KU5cT1JKA37lc+ynfOGINiK4E14hJItnfINAxfyUXdsEbVKS Y8ST0DVsn9HES1YmPNhU1MGD+6aFDC3zwp3fO7ck6q2uX7mpipUjcRJ8OOocwHA3gset L6Hg0grwU1my5HNWOzIsgz38RoKJsQ2C7oyGTKhLKdgU4cPKeUt4n62TDVLy0QzzDQHU CcRg== X-Gm-Message-State: ABUngvd8T7e2lmharReheOoPembNwhBe8aFHltjA+c/4rrM5pbRmaX0noDODDvp0pSjR9HoSWwfwKikoIBZByxK9 X-Received: by 10.107.2.8 with SMTP id 8mr6143796ioc.83.1478196302757; Thu, 03 Nov 2016 11:05:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.59.147 with HTTP; Thu, 3 Nov 2016 11:05:02 -0700 (PDT) In-Reply-To: <35e6e483-afcf-b735-c3ef-55236ac83423@redhat.com> References: <1478194274-16524-1-git-send-email-ard.biesheuvel@linaro.org> <35e6e483-afcf-b735-c3ef-55236ac83423@redhat.com> From: Ard Biesheuvel Date: Thu, 3 Nov 2016 18:05:02 +0000 Message-ID: To: Laszlo Ersek Cc: "edk2-devel@lists.01.org" , "Kinney, Michael D" , "Gao, Liming" Subject: Re: [PATCH] MdePkg/BaseMemoryLibOptDxe: 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: Thu, 03 Nov 2016 18:05:02 -0000 Content-Type: text/plain; charset=UTF-8 On 3 November 2016 at 17:38, Laszlo Ersek wrote: > On 11/03/16 18:31, Ard Biesheuvel wrote: >> 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. >> >> Contributed-under: TianoCore Contribution Agreement 1.0 >> Signed-off-by: Ard Biesheuvel >> --- >> MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c b/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c >> index 2a0a038fd6c5..fbc2f5742c8c 100644 >> --- a/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c >> +++ b/MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c >> @@ -46,6 +46,10 @@ ZeroMem ( >> IN UINTN Length >> ) >> { >> + if (Length == 0) { >> + return Buffer; >> + } >> + >> ASSERT (!(Buffer == NULL && Length > 0)); >> ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1)); >> return InternalMemZeroMem (Buffer, Length); >> > > 1. Why is this necessary? > The 32-bit accelerated ARM code writes at least one byte, and given that the other string functions take the same shortcut, this seemed the most appropriate way to fix that. > 2. After the new check, Length is guaranteed to be positive. The first > ASSERT() should be updated (simplified), I think: > > ASSERT (Buffer != NULL); > Good point. I will change that