From 94020bb40f12a9057aed2dfaa89ad35d644d704e Mon Sep 17 00:00:00 2001 From: rsun3 Date: Wed, 14 Mar 2012 03:17:17 +0000 Subject: Improve robustness when scanning PCI Option ROM. Signed-off-by: rsun3 Reviewed-by: geekboy15a git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13095 6f19259b-4bc3-4df7-8a09-765794883524 --- DuetPkg/PciRootBridgeNoEnumerationDxe/Ia32/PcatIo.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'DuetPkg/PciRootBridgeNoEnumerationDxe/Ia32') diff --git a/DuetPkg/PciRootBridgeNoEnumerationDxe/Ia32/PcatIo.c b/DuetPkg/PciRootBridgeNoEnumerationDxe/Ia32/PcatIo.c index 7395ce2d8b..fbfc2fadef 100644 --- a/DuetPkg/PciRootBridgeNoEnumerationDxe/Ia32/PcatIo.c +++ b/DuetPkg/PciRootBridgeNoEnumerationDxe/Ia32/PcatIo.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2005 - 2008, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -436,8 +436,10 @@ CheckForRom ( Pcir.ImageLength = 0; - if (EfiRomHeader.Signature == 0xaa55) { - + if (EfiRomHeader.Signature == PCI_EXPANSION_ROM_HEADER_SIGNATURE && + EfiRomHeader.PcirOffset != 0 && + (EfiRomHeader.PcirOffset & 3) == 0 && + RomBarSize + EfiRomHeader.PcirOffset + sizeof (PCI_DATA_STRUCTURE) <= MaxRomSize) { ZeroMem (&Pcir, sizeof(Pcir)); IoDev->Mem.Read ( IoDev, @@ -447,6 +449,12 @@ CheckForRom ( &Pcir ); + if (Pcir.Signature != PCI_DATA_STRUCTURE_SIGNATURE) { + break; + } + if (RomBarSize + Pcir.ImageLength * 512 > MaxRomSize) { + break; + } if ((Pcir.Indicator & 0x80) == 0x00) { LastImage = FALSE; } -- cgit v1.2.3