[HAL] Fix more bugs in HalpDebugPciDumpBus (#1939)

- Don't match device id outside current vendor id list.
- Don't match subsystem id outside current device id list.
- Refactor some magic constants.

Addendum to 894635b.
This commit is contained in:
Stanislav Motylkov 2019-09-28 19:30:56 +03:00 committed by Hermès BÉLUSCA - MAÏTO
parent 6ec38aa942
commit 07706eca3a

View file

@ -809,10 +809,10 @@ HalpDebugPciDumpBus(IN ULONG i,
IN ULONG k, IN ULONG k,
IN PPCI_COMMON_CONFIG PciData) IN PPCI_COMMON_CONFIG PciData)
{ {
PCHAR p, ClassName, ClassEnd, SubClassName, VendorName, ProductName, SubVendorName; PCHAR p, ClassName, Boundary, SubClassName, VendorName, ProductName, SubVendorName;
ULONG Length; ULONG Length;
CHAR LookupString[16] = ""; CHAR LookupString[16] = "";
CHAR bSubClassName[64] = ""; CHAR bSubClassName[64] = "Unknown";
CHAR bVendorName[64] = ""; CHAR bVendorName[64] = "";
CHAR bProductName[128] = "Unknown device"; CHAR bProductName[128] = "Unknown device";
CHAR bSubVendorName[128] = "Unknown"; CHAR bSubVendorName[128] = "Unknown";
@ -825,10 +825,10 @@ HalpDebugPciDumpBus(IN ULONG i,
{ {
/* Isolate the subclass name */ /* Isolate the subclass name */
ClassName += strlen("C 00 "); ClassName += strlen("C 00 ");
ClassEnd = strstr(ClassName, "\nC "); Boundary = strstr(ClassName, "\nC ");
sprintf(LookupString, "\n\t%02x ", PciData->SubClass); sprintf(LookupString, "\n\t%02x ", PciData->SubClass);
SubClassName = strstr(ClassName, LookupString); SubClassName = strstr(ClassName, LookupString);
if (ClassEnd && SubClassName > ClassEnd) if (Boundary && SubClassName > Boundary)
{ {
SubClassName = NULL; SubClassName = NULL;
} }
@ -854,25 +854,43 @@ HalpDebugPciDumpBus(IN ULONG i,
if (VendorName) if (VendorName)
{ {
/* Copy the vendor name into our buffer */ /* Copy the vendor name into our buffer */
VendorName += 8; VendorName += strlen("\r\n0000 ");
p = strpbrk(VendorName, "\r\n"); p = strpbrk(VendorName, "\r\n");
Length = p - VendorName; Length = p - VendorName;
if (Length >= sizeof(bVendorName)) Length = sizeof(bVendorName) - 1; if (Length >= sizeof(bVendorName)) Length = sizeof(bVendorName) - 1;
strncpy(bVendorName, VendorName, Length); strncpy(bVendorName, VendorName, Length);
bVendorName[Length] = '\0'; bVendorName[Length] = '\0';
p += strlen("\r\n");
while (*p == '\t' || *p == '#')
{
p = strpbrk(p, "\r\n");
p += strlen("\r\n");
}
Boundary = p;
/* Isolate the product name */ /* Isolate the product name */
sprintf(LookupString, "\t%04x ", PciData->DeviceID); sprintf(LookupString, "\t%04x ", PciData->DeviceID);
ProductName = strstr(VendorName, LookupString); ProductName = strstr(VendorName, LookupString);
if (Boundary && ProductName >= Boundary)
{
ProductName = NULL;
}
if (ProductName) if (ProductName)
{ {
/* Copy the product name into our buffer */ /* Copy the product name into our buffer */
ProductName += 7; ProductName += strlen("\t0000 ");
p = strpbrk(ProductName, "\r\n"); p = strpbrk(ProductName, "\r\n");
Length = p - ProductName; Length = p - ProductName;
if (Length >= sizeof(bProductName)) Length = sizeof(bProductName) - 1; if (Length >= sizeof(bProductName)) Length = sizeof(bProductName) - 1;
strncpy(bProductName, ProductName, Length); strncpy(bProductName, ProductName, Length);
bProductName[Length] = '\0'; bProductName[Length] = '\0';
p += strlen("\r\n");
while ((*p == '\t' && *(p + 1) == '\t') || *p == '#')
{
p = strpbrk(p, "\r\n");
p += strlen("\r\n");
}
Boundary = p;
/* Isolate the subvendor and subsystem name */ /* Isolate the subvendor and subsystem name */
sprintf(LookupString, sprintf(LookupString,
@ -880,10 +898,14 @@ HalpDebugPciDumpBus(IN ULONG i,
PciData->u.type0.SubVendorID, PciData->u.type0.SubVendorID,
PciData->u.type0.SubSystemID); PciData->u.type0.SubSystemID);
SubVendorName = strstr(ProductName, LookupString); SubVendorName = strstr(ProductName, LookupString);
if (Boundary && SubVendorName >= Boundary)
{
SubVendorName = NULL;
}
if (SubVendorName) if (SubVendorName)
{ {
/* Copy the subvendor name into our buffer */ /* Copy the subvendor name into our buffer */
SubVendorName += 13; SubVendorName += strlen("\t\t0000 0000 ");
p = strpbrk(SubVendorName, "\r\n"); p = strpbrk(SubVendorName, "\r\n");
Length = p - SubVendorName; Length = p - SubVendorName;
if (Length >= sizeof(bSubVendorName)) Length = sizeof(bSubVendorName) - 1; if (Length >= sizeof(bSubVendorName)) Length = sizeof(bSubVendorName) - 1;