From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web12.6977.1667124394139932328 for ; Sun, 30 Oct 2022 03:06:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eUcOVfjx; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6965360E93 for ; Sun, 30 Oct 2022 10:06:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8CF3C433C1 for ; Sun, 30 Oct 2022 10:06:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667124392; bh=XQAqaY02p5pugl8rww1CXa1PIlsM18Ero9Sc8TNuZ5Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eUcOVfjxpRK+wY4wbX9gpOZT/ZAKiaSV+z4Qx7ViDfkbcJiZsc+zMBlqmTP7E6Uld d5h3VgqZ+7JAgVzUMLuSOeyuO63qdLvJ26dKqtvTRqjaQFCUPczGPbw21vd5fGLBd9 keZjDotw08laNGQ7T2oYdUAr5VvbGd7rcXvjp9ylxLRDPgXalzub1EHIZfyWna+nvi YdtwMs1dOMcDQfHCM3ZAsrFMEaWIe9IxBh+o6j7tTxYvAEkY6FzeB4igjG6rlqkACW x704iiEDoTHJyq4txGNzUJh4H8hsfPHnTzUAgqCWa5r4GFAYqsPjrXRDAV6B5kgxlN /27Xitg3zk2ig== Received: by mail-lf1-f48.google.com with SMTP id g7so15060790lfv.5 for ; Sun, 30 Oct 2022 03:06:32 -0700 (PDT) X-Gm-Message-State: ACrzQf0Xtt8T3ZDqip7lK8wEaF3mk7NtOrn05A/Kq13ABmVxcRNOs51Y dV1J2qDQ4qgggO0ZT2buNxU4h2+hUU4hrE4Xxu0= X-Google-Smtp-Source: AMsMyM7NIC9qBJENkSqlyxBtgwS6PCUynaMDtADlFLahi+Wia4nrW+pLhSTzx4uB3kI1BgEFfqrpnY4Pv5GVKx7rt2Q= X-Received: by 2002:a05:6512:151b:b0:4af:e7d3:4a46 with SMTP id bq27-20020a056512151b00b004afe7d34a46mr3013335lfb.583.1667124390783; Sun, 30 Oct 2022 03:06:30 -0700 (PDT) MIME-Version: 1.0 References: <20221029092854.3377294-1-xiewenyi2@huawei.com> <20221029092854.3377294-2-xiewenyi2@huawei.com> In-Reply-To: <20221029092854.3377294-2-xiewenyi2@huawei.com> From: "Ard Biesheuvel" Date: Sun, 30 Oct 2022 11:06:19 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH EDK2 v1 1/1] ArmPlatformPkg/Drivers/NorFlashDxe:avoid index out of bound To: Wenyi Xie Cc: devel@edk2.groups.io, quic_llindhol@quicinc.com, ardb+tianocore@kernel.org, songdongkuang@huawei.com Content-Type: text/plain; charset="UTF-8" On Sat, 29 Oct 2022 at 11:29, Wenyi Xie wrote: > > The size of array BlockMap is 1 in struct FirmwareVolumeHeader, but in > function InitializeFvAndVariableStoreHeaders, BlockMap[1] is been written. The size of BlockMap[] is not 1. BlockMap is a flexible array declared in an old fashioned way, and because the type definition is covered by the spec, we can not change it. Given that this is established idiom, compilers don't tend to warn about this. > 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 Thanks for the patch but this driver is going to be deleted soon so no point. There is new version of this driver in OvmfPkg/ but given the above, I don't think there is anything that needs fixing here. > --- > 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 >