Skip to content

Commit 894635b

Browse files
binarymasterHBelusca
authored andcommitted
[HAL] Fix parser bugs in HalpDebugPciDumpBus (reactos#1895)
- Match subclass properly, don't match third subclass. - Don't match subclass from next class, add ClassEnd boundary. - Use class name if subclass name not available. - Gracefully return "Unknown" if no class name found.
1 parent 43f03da commit 894635b

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

hal/halx86/legacy/bussupp.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ HalpDebugPciDumpBus(IN ULONG i,
809809
IN ULONG k,
810810
IN PPCI_COMMON_CONFIG PciData)
811811
{
812-
PCHAR p, ClassName, SubClassName, VendorName, ProductName, SubVendorName;
812+
PCHAR p, ClassName, ClassEnd, SubClassName, VendorName, ProductName, SubVendorName;
813813
ULONG Length;
814814
CHAR LookupString[16] = "";
815815
CHAR bSubClassName[64] = "";
@@ -824,19 +824,28 @@ HalpDebugPciDumpBus(IN ULONG i,
824824
if (ClassName)
825825
{
826826
/* Isolate the subclass name */
827-
ClassName += 6;
828-
sprintf(LookupString, "\t%02x ", PciData->SubClass);
827+
ClassName += strlen("C 00 ");
828+
ClassEnd = strstr(ClassName, "\nC ");
829+
sprintf(LookupString, "\n\t%02x ", PciData->SubClass);
829830
SubClassName = strstr(ClassName, LookupString);
830-
if (SubClassName)
831+
if (ClassEnd && SubClassName > ClassEnd)
831832
{
832-
/* Copy the subclass into our buffer */
833-
SubClassName += 5;
834-
p = strpbrk(SubClassName, "\r\n");
835-
Length = p - SubClassName;
836-
if (Length >= sizeof(bSubClassName)) Length = sizeof(bSubClassName) - 1;
837-
strncpy(bSubClassName, SubClassName, Length);
838-
bSubClassName[Length] = '\0';
833+
SubClassName = NULL;
839834
}
835+
if (!SubClassName)
836+
{
837+
SubClassName = ClassName;
838+
}
839+
else
840+
{
841+
SubClassName += strlen("\n\t00 ");
842+
}
843+
/* Copy the subclass into our buffer */
844+
p = strpbrk(SubClassName, "\r\n");
845+
Length = p - SubClassName;
846+
if (Length >= sizeof(bSubClassName)) Length = sizeof(bSubClassName) - 1;
847+
strncpy(bSubClassName, SubClassName, Length);
848+
bSubClassName[Length] = '\0';
840849
}
841850

842851
/* Isolate the vendor name */

0 commit comments

Comments
 (0)