From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mx.groups.io with SMTP id smtpd.web10.1781.1667035744968008214 for ; Sat, 29 Oct 2022 02:29:05 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.188, mailfrom: xiewenyi2@huawei.com) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MzvHL6vmGzHvJ7; Sat, 29 Oct 2022 17:28:46 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 29 Oct 2022 17:29:02 +0800 Received: from kwephisprg16640.huawei.com (10.247.83.252) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 29 Oct 2022 17:29:01 +0800 From: "wenyi,xie" To: , , CC: , Subject: [PATCH EDK2 v1 1/1] ArmPlatformPkg/Drivers/NorFlashDxe:avoid index out of bound Date: Sat, 29 Oct 2022 17:28:54 +0800 Message-ID: <20221029092854.3377294-2-xiewenyi2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20221029092854.3377294-1-xiewenyi2@huawei.com> References: <20221029092854.3377294-1-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.247.83.252] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected Content-Type: text/plain 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 Cc: Ard Biesheuvel Signed-off-by: Wenyi Xie --- 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