From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Cc: lersek@redhat.com, jaben.carsey@intel.com, Ard Biesheuvel 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: [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: , X-List-Received-Date: Thu, 03 Nov 2016 18:18:18 -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. 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(-) 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); } -- 2.7.4