https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5caa59b31abc86a481f49…
commit 5caa59b31abc86a481f495102cd83984b604bffc
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Mon May 24 17:24:24 2021 +0300
Commit: Stanislav Motylkov <x86corez(a)gmail.com>
CommitDate: Mon May 24 17:24:24 2021 +0300
[HAL] HalpDebugPciDumpBus: Fix parsing bugs
- Bridge devices don't have Subsystem ID and Subsystem Vendor ID
- Also they have only two BARs, don't parse data outside of bounds
Addendum to b232efe1. CORE-16319 CORE-16216
---
hal/halx86/legacy/bussupp.c | 49 ++++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/hal/halx86/legacy/bussupp.c b/hal/halx86/legacy/bussupp.c
index 4b855ec596e..6e291d58479 100644
--- a/hal/halx86/legacy/bussupp.c
+++ b/hal/halx86/legacy/bussupp.c
@@ -791,6 +791,7 @@ HalpDebugPciDumpBus(IN ULONG i,
IN PPCI_COMMON_CONFIG PciData)
{
PCHAR p, ClassName, Boundary, SubClassName, VendorName, ProductName, SubVendorName;
+ UCHAR HeaderType;
ULONG Length;
CHAR LookupString[16] = "";
CHAR bSubClassName[64] = "Unknown";
@@ -799,6 +800,8 @@ HalpDebugPciDumpBus(IN ULONG i,
CHAR bSubVendorName[128] = "Unknown";
ULONG Size, Mem, b;
+ HeaderType = (PciData->HeaderType & ~PCI_MULTIFUNCTION);
+
/* Isolate the class name */
sprintf(LookupString, "C %02x ", PciData->BaseClass);
ClassName = strstr((PCHAR)ClassTable, LookupString);
@@ -872,16 +875,20 @@ HalpDebugPciDumpBus(IN ULONG i,
p += strlen("\r\n");
}
Boundary = p;
+ SubVendorName = NULL;
- /* Isolate the subvendor and subsystem name */
- sprintf(LookupString,
- "\t\t%04x %04x ",
- PciData->u.type0.SubVendorID,
- PciData->u.type0.SubSystemID);
- SubVendorName = strstr(ProductName, LookupString);
- if (Boundary && SubVendorName >= Boundary)
+ if (HeaderType == PCI_DEVICE_TYPE)
{
- SubVendorName = NULL;
+ /* Isolate the subvendor and subsystem name */
+ sprintf(LookupString,
+ "\t\t%04x %04x ",
+ PciData->u.type0.SubVendorID,
+ PciData->u.type0.SubSystemID);
+ SubVendorName = strstr(ProductName, LookupString);
+ if (Boundary && SubVendorName >= Boundary)
+ {
+ SubVendorName = NULL;
+ }
}
if (SubVendorName)
{
@@ -897,8 +904,7 @@ HalpDebugPciDumpBus(IN ULONG i,
}
/* Print out the data */
- DbgPrint("%02x:%02x.%x %s [%02x%02x]: %s %s [%04x:%04x] (rev %02x)\n"
- "\tSubsystem: %s [%04x:%04x]\n",
+ DbgPrint("%02x:%02x.%x %s [%02x%02x]: %s %s [%04x:%04x] (rev %02x)\n",
i,
j,
k,
@@ -909,10 +915,15 @@ HalpDebugPciDumpBus(IN ULONG i,
bProductName,
PciData->VendorID,
PciData->DeviceID,
- PciData->RevisionID,
- bSubVendorName,
- PciData->u.type0.SubVendorID,
- PciData->u.type0.SubSystemID);
+ PciData->RevisionID);
+
+ if (HeaderType == PCI_DEVICE_TYPE)
+ {
+ DbgPrint("\tSubsystem: %s [%04x:%04x]\n",
+ bSubVendorName,
+ PciData->u.type0.SubVendorID,
+ PciData->u.type0.SubSystemID);
+ }
/* Print out and decode flags */
DbgPrint("\tFlags:");
@@ -929,8 +940,7 @@ HalpDebugPciDumpBus(IN ULONG i,
else if (PciData->u.type0.InterruptPin != 0) DbgPrint(", IRQ assignment
required");
DbgPrint("\n");
- if ((PciData->HeaderType & ~PCI_MULTIFUNCTION) == PCI_BRIDGE_TYPE &&
- PciData->BaseClass == PCI_CLASS_BRIDGE_DEV)
+ if (HeaderType == PCI_BRIDGE_TYPE)
{
DbgPrint("\tBridge:");
DbgPrint(" primary bus %d,", PciData->u.type1.PrimaryBus);
@@ -942,10 +952,13 @@ HalpDebugPciDumpBus(IN ULONG i,
/* Scan addresses */
Size = 0;
- for (b = 0; b < PCI_TYPE0_ADDRESSES; b++)
+ for (b = 0; b < (HeaderType == PCI_DEVICE_TYPE ? PCI_TYPE0_ADDRESSES :
PCI_TYPE1_ADDRESSES); b++)
{
/* Check for a BAR */
- Mem = PciData->u.type0.BaseAddresses[b];
+ if (HeaderType != PCI_CARDBUS_BRIDGE_TYPE)
+ Mem = PciData->u.type0.BaseAddresses[b];
+ else
+ Mem = 0;
if (Mem)
{
/* Decode the address type */