[edk2-devel] [PATCH v1 2/3] MdeModulePkg/PciBusDxe: Fix possible uninitialized use

Ni, Ray ray.ni at intel.com
Mon May 17 02:05:39 UTC 2021


How about below fix? I think it might be simpler to understand and doesn't introduce unnecessary logic to handle impossible case:
    if (ResizableBarOp == PciResizableBarMax) {
      Bit = HighBitSet64(Capabilities);
    } else {
      ASSERT (ResizableBarOp == PciResizableBarMin);
      Bit = LowBitSet64(Capabilities);
    }

> -----Original Message-----
> From: Sergei Dmitrouk <sergei at posteo.net>
> Sent: Friday, May 14, 2021 8:17 PM
> To: devel at edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang at intel.com>; Wu, Hao A <hao.a.wu at intel.com>;
> Ni, Ray <ray.ni at intel.com>
> Subject: [PATCH v1 2/3] MdeModulePkg/PciBusDxe: Fix possible uninitialized
> use
> 
> If the function gets invalid value for the `ResizableBarOp` parameter
> and asserts are disabled, `Bit` can be used uninitialized.
> 
> Cc: Jian J Wang <jian.j.wang at intel.com>
> Cc: Hao A Wu <hao.a.wu at intel.com>
> Cc: Ray Ni <ray.ni at intel.com>
> Signed-off-by: Sergei Dmitrouk <sergei at posteo.net>
> ---
>  MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
> b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
> index 6bba28367165..de601713a53b 100644
> --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
> +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
> @@ -1781,6 +1781,11 @@ PciProgramResizableBar (
>      } else if (ResizableBarOp == PciResizableBarMin) {
>        Bit = LowBitSet64(Capabilities);
>      } else {
> +      //
> +      // Set Bit to avoid uninitialized use when built without assertions.
> +      //
> +      Bit = 0;
> +
>        ASSERT ((ResizableBarOp == PciResizableBarMax) || (ResizableBarOp ==
> PciResizableBarMin));
>      }
> 
> --
> 2.17.6



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#75158): https://edk2.groups.io/g/devel/message/75158
Mute This Topic: https://groups.io/mt/82822573/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list