From patchwork Thu Nov 3 18:18:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 80715 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp773268qge; Thu, 3 Nov 2016 11:18:22 -0700 (PDT) X-Received: by 10.98.76.194 with SMTP id e63mr18945537pfj.95.1478197102701; Thu, 03 Nov 2016 11:18:22 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id j11si11054880pga.164.2016.11.03.11.18.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Nov 2016 11:18:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2167381D3D; Thu, 3 Nov 2016 11:18:20 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com [IPv6:2a00:1450:400c:c09::229]) (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 5A07E81D36 for ; Thu, 3 Nov 2016 11:18:18 -0700 (PDT) Received: by mail-wm0-x229.google.com with SMTP id p190so3828344wmp.1 for ; Thu, 03 Nov 2016 11:18:20 -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=9xF6zW6WHPEuVNy2yTWWkkZDPusMq9VYLm5S/bUjdx0=; b=Ci/Kx5wFInOdFoF+kkSr9uS6xZe69X5lcoMa7cBeDNvSCRRnCWyWXkC4qi+1h1dHFq 9D8Pkp2msX1jYbu+HOEiDN3kB9Zg80kFp3u27fD/4UfKz+UYo+ZyOkJLiyt0lQkfeF5i pUiXuqSFZr47rBhcJp2+w5Ff9KcXd+j4Km61w= 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=9xF6zW6WHPEuVNy2yTWWkkZDPusMq9VYLm5S/bUjdx0=; b=mAA9tVuPoPuHW8HjGaSM25leTD+hUH2M3EoCWF7Y9vdvHnu9Sc1BKQcNZaCG2gBhrp FveJgVKsbeKgJQwvOsnPuXZ3Ysa6x76LSoNLmwIzDjaDhXh7WMLcT/LmVX5vaADmB7/o BVbRTecTRr1drcf2pmCo64zf0p1+O+LP2Ekqkj3I+nmRO/VWzRSRxo84N8qlwJTjMKcq 6GOyJVw9FPWsPpLbK3BfzUJpAflsJVvBurMsCSugAKpnp4yqG89vTWvZs40xeKu6KDGb U1yHCYSYXGAkpjHXSABu7NN8G61/n4aCjgBUgm+8EGyEi48AvlDxa36Qf7N1Z5eNGnEw NWYA== X-Gm-Message-State: ABUngvfDBWWyghXIbZI1w7BgvZ/gCKnaAuxr/MBIs0GL4Wyz8xzYlEgr2jG9NV6b4qeMM9n1 X-Received: by 10.194.115.230 with SMTP id jr6mr8458781wjb.3.1478197098871; Thu, 03 Nov 2016 11:18:18 -0700 (PDT) Received: from localhost.localdomain ([105.151.153.127]) by smtp.gmail.com with ESMTPSA id 71sm288783wmo.7.2016.11.03.11.18.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Nov 2016 11:18:18 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, michael.d.kinney@intel.com, liming.gao@intel.com Date: Thu, 3 Nov 2016 18:18:13 +0000 Message-Id: <1478197093-17209-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [PATCH v2] 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: , Cc: jaben.carsey@intel.com, lersek@redhat.com, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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. This fixes an issue with the ARM implementation, 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 --- MdePkg/Library/BaseMemoryLibOptDxe/ZeroMemWrapper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Acked-by: Laszlo Ersek 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); }