Index: drivers/video/videoprt/videoprt.c =================================================================== --- drivers/video/videoprt/videoprt.c (revision 51378) +++ drivers/video/videoprt/videoprt.c (working copy) @@ -73,53 +73,83 @@ ((PMINIPORT_DPC_ROUTINE)SystemArgument1)(HwDeviceExtension, SystemArgument2); } +static BOOLEAN UnicodeStringStartsWith( + IN PCUNICODE_STRING Haystack, + IN PCUNICODE_STRING Needle, + IN BOOLEAN CaseInSensitive) +{ + UNICODE_STRING HaystackStart; + + if (Haystack->Length < Needle->Length) + return FALSE; + + HaystackStart = *Haystack; + HaystackStart.Length = Needle->Length; + + return RtlCompareUnicodeString(&HaystackStart, Needle, CaseInSensitive) == 0; +} + +static BOOLEAN SkipIfUnicodeStartsWithString( + IN OUT PUNICODE_STRING Haystack, + IN PCWSTR NeedleString, + IN BOOLEAN CaseInSensitive) +{ + UNICODE_STRING Needle; + + RtlInitUnicodeString(&Needle, NeedleString); + + if (!UnicodeStringStartsWith(Haystack, &Needle, CaseInSensitive)) + return FALSE; + + Haystack->Buffer += Needle.Length / sizeof Needle.Buffer[0]; + Haystack->Length -= Needle.Length; + Haystack->MaximumLength -= Needle.Length; + + return TRUE; +} + +static VOID SkipCharUnicodeString( + IN OUT PUNICODE_STRING String) +{ + String->Buffer++; + String->Length -= sizeof String->Buffer[0]; + String->MaximumLength -= sizeof String->Buffer[0]; +} + NTSTATUS IntCreateRegistryPath( IN PCUNICODE_STRING DriverRegistryPath, OUT PUNICODE_STRING DeviceRegistryPath) { - static WCHAR RegistryMachineSystem[] = L"\\REGISTRY\\MACHINE\\SYSTEM\\"; - static WCHAR CurrentControlSet[] = L"CURRENTCONTROLSET\\"; - static WCHAR ControlSet[] = L"CONTROLSET"; - static WCHAR Insert1[] = L"Hardware Profiles\\Current\\System\\CurrentControlSet\\"; - static WCHAR Insert2[] = L"\\Device0"; + static const WCHAR RegistryMachineSystem[] = L"\\REGISTRY\\MACHINE\\SYSTEM\\"; + static const WCHAR CurrentControlSet[] = L"CURRENTCONTROLSET\\"; + static const WCHAR ControlSet[] = L"CONTROLSET"; + static const WCHAR Insert1[] = L"Hardware Profiles\\Current\\System\\CurrentControlSet\\"; + static const WCHAR Insert2[] = L"\\Device0"; BOOLEAN Valid; UNICODE_STRING AfterControlSet; AfterControlSet = *DriverRegistryPath; /* Check if path begins with \\REGISTRY\\MACHINE\\SYSTEM\\ */ - Valid = (DriverRegistryPath->Length > sizeof(RegistryMachineSystem) && - 0 == _wcsnicmp(DriverRegistryPath->Buffer, RegistryMachineSystem, - wcslen(RegistryMachineSystem))); + Valid = SkipIfUnicodeStartsWithString(&AfterControlSet, RegistryMachineSystem, TRUE); if (Valid) { - AfterControlSet.Buffer += wcslen(RegistryMachineSystem); - AfterControlSet.Length -= sizeof(RegistryMachineSystem) - sizeof(UNICODE_NULL); - /* Check if path contains CURRENTCONTROLSET */ - if (AfterControlSet.Length > sizeof(CurrentControlSet) && - 0 == _wcsnicmp(AfterControlSet.Buffer, CurrentControlSet, wcslen(CurrentControlSet))) + if (SkipIfUnicodeStartsWithString(&AfterControlSet, CurrentControlSet, TRUE)) { - AfterControlSet.Buffer += wcslen(CurrentControlSet); - AfterControlSet.Length -= sizeof(CurrentControlSet) - sizeof(UNICODE_NULL); + Valid = TRUE; } /* Check if path contains CONTROLSETnum */ - else if (AfterControlSet.Length > sizeof(ControlSet) && - 0 == _wcsnicmp(AfterControlSet.Buffer, ControlSet, wcslen(ControlSet))) + else if (SkipIfUnicodeStartsWithString(&AfterControlSet, ControlSet, TRUE)) { - AfterControlSet.Buffer += wcslen(ControlSet); - AfterControlSet.Length -= sizeof(ControlSet) - sizeof(UNICODE_NULL); while (AfterControlSet.Length > 0 && *AfterControlSet.Buffer >= L'0' && *AfterControlSet.Buffer <= L'9') { - AfterControlSet.Buffer++; - AfterControlSet.Length -= sizeof(WCHAR); + SkipCharUnicodeString(&AfterControlSet); } Valid = (AfterControlSet.Length > 0 && L'\\' == *AfterControlSet.Buffer); - AfterControlSet.Buffer++; - AfterControlSet.Length -= sizeof(WCHAR); - AfterControlSet.MaximumLength = AfterControlSet.Length; + SkipCharUnicodeString(&AfterControlSet); } else { @@ -136,10 +166,11 @@ if (DeviceRegistryPath->Buffer != NULL) { /* Build device path */ - wcsncpy(DeviceRegistryPath->Buffer, - DriverRegistryPath->Buffer, - AfterControlSet.Buffer - DriverRegistryPath->Buffer); DeviceRegistryPath->Length = (AfterControlSet.Buffer - DriverRegistryPath->Buffer) * sizeof(WCHAR); + RtlCopyMemory(DeviceRegistryPath->Buffer, + DriverRegistryPath->Buffer, + DeviceRegistryPath->Length); + RtlAppendUnicodeToString(DeviceRegistryPath, Insert1); RtlAppendUnicodeStringToString(DeviceRegistryPath, &AfterControlSet); RtlAppendUnicodeToString(DeviceRegistryPath, Insert2);