[NTOS:IO] Don't uppercase the ServiceName in IopDisplayLoadingMessage().

Problematic behaviour was added in commit a97f262ed (r26067), and
commit c39812d1b (r46193) converted to RtlUpcaseUnicodeString() call.

This was modifying the caller's given string. This is not really
a good practice to do so just to make display fancier.

For example, IopInitializeBuiltinDriver(), that calls the display
function, also uses the passed ServiceName later after.

Because IopDisplayLoadingMessage() executes only in SOS mode,
uppercasing the ServiceName in one case but not the other would
implicitly modify the observable OS behaviour.

IopSuffixUnicodeString() is adapted to be similar to RtlPrefixUnicodeString().
This commit is contained in:
Hermès Bélusca-Maïto 2024-02-07 21:53:52 +01:00
parent 3b60f4fa13
commit 475098c8b1
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -279,7 +279,8 @@ Cleanup:
static BOOLEAN
IopSuffixUnicodeString(
_In_ PCUNICODE_STRING String1,
_In_ PCUNICODE_STRING String2)
_In_ PCUNICODE_STRING String2,
_In_ BOOLEAN CaseInSensitive)
{
PWCHAR pc1, pc2;
ULONG NumChars;
@ -293,13 +294,29 @@ IopSuffixUnicodeString(
if (pc1 && pc2)
{
while (NumChars--)
if (CaseInSensitive)
{
if (*pc1++ != *pc2++)
return FALSE;
while (NumChars--)
{
if (RtlUpcaseUnicodeChar(*pc1++) !=
RtlUpcaseUnicodeChar(*pc2++))
{
return FALSE;
}
}
}
else
{
while (NumChars--)
{
if (*pc1++ != *pc2++)
return FALSE;
}
}
return TRUE;
}
return FALSE;
}
@ -309,7 +326,7 @@ IopSuffixUnicodeString(
static VOID
FASTCALL
IopDisplayLoadingMessage(
_In_ PUNICODE_STRING ServiceName)
_In_ PCUNICODE_STRING ServiceName)
{
extern BOOLEAN SosEnabled; // See ex/init.c
static const UNICODE_STRING DotSys = RTL_CONSTANT_STRING(L".SYS");
@ -317,13 +334,13 @@ IopDisplayLoadingMessage(
if (!SosEnabled) return;
if (!KeLoaderBlock) return;
RtlUpcaseUnicodeString(ServiceName, ServiceName, FALSE);
RtlStringCbPrintfA(TextBuffer, sizeof(TextBuffer),
"%s%sSystem32\\Drivers\\%wZ%s\r\n",
KeLoaderBlock->ArcBootDeviceName,
KeLoaderBlock->NtBootPathName,
ServiceName,
IopSuffixUnicodeString(&DotSys, ServiceName) ? "" : ".SYS");
IopSuffixUnicodeString(&DotSys, ServiceName, TRUE)
? "" : ".SYS");
HalDisplayString(TextBuffer);
}