public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "wenyi,xie" <xiewenyi2@huawei.com>
To: <devel@edk2.groups.io>, <quic_llindhol@quicinc.com>,
	<ardb+tianocore@kernel.org>
Cc: <songdongkuang@huawei.com>, <xiewenyi2@huawei.com>
Subject: [PATCH EDK2 v1 1/1] ArmPlatformPkg/Drivers/NorFlashDxe:avoid index out of bound
Date: Sat, 29 Oct 2022 17:28:54 +0800	[thread overview]
Message-ID: <20221029092854.3377294-2-xiewenyi2@huawei.com> (raw)
In-Reply-To: <20221029092854.3377294-1-xiewenyi2@huawei.com>

The size of array BlockMap is 1 in struct FirmwareVolumeHeader, but in
function InitializeFvAndVariableStoreHeaders, BlockMap[1] is been written.
The memory of BlockMap[1] is already allocated, so the code is OK. But
it is better to use a new point to assign this memory.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
---
 ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
index 0767581308d2..2130e2e76344 100644
--- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
@@ -47,6 +47,7 @@ InitializeFvAndVariableStoreHeaders (
   VOID                        *Headers;
   UINTN                       HeadersLength;
   EFI_FIRMWARE_VOLUME_HEADER  *FirmwareVolumeHeader;
+  EFI_FV_BLOCK_MAP_ENTRY      *BlockMapEntry;
   VARIABLE_STORE_HEADER       *VariableStoreHeader;
   UINT32                      NvStorageFtwSpareSize;
   UINT32                      NvStorageFtwWorkingSize;
@@ -151,10 +152,15 @@ InitializeFvAndVariableStoreHeaders (
   FirmwareVolumeHeader->Revision              = EFI_FVH_REVISION;
   FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1;
   FirmwareVolumeHeader->BlockMap[0].Length    = Instance->Media.BlockSize;
-  FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;
-  FirmwareVolumeHeader->BlockMap[1].Length    = 0;
   FirmwareVolumeHeader->Checksum              = CalculateCheckSum16 ((UINT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength);
 
+  //
+  // EFI_FV_BLOCK_MAP_ENTRY
+  //
+  BlockMapEntry            = (EFI_FV_BLOCK_MAP_ENTRY *)((UINTN)Headers + sizeof (EFI_FIRMWARE_VOLUME_HEADER));
+  BlockMapEntry->NumBlocks = 0;
+  BlockMapEntry->Length    = 0;
+
   //
   // VARIABLE_STORE_HEADER
   //
-- 
2.20.1.windows.1


  reply	other threads:[~2022-10-29  9:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-29  9:28 [PATCH EDK2 v1 0/1] ArmPlatformPkg/Drivers/NorFlashDxe:avoid index out of bound wenyi,xie
2022-10-29  9:28 ` wenyi,xie [this message]
2022-10-30 10:06   ` [PATCH EDK2 v1 1/1] " Ard Biesheuvel
2022-10-31  1:24     ` wenyi,xie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221029092854.3377294-2-xiewenyi2@huawei.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox