From 0d6d9c18ccd8df352cd8d30773b642574783e53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 3 Jun 2016 19:02:46 +0000 Subject: [PATCH] [NTDLL] - In LdrpLoadImportModule, check for import module extension, and append it if not found. - Fix LdrpLoadImportModule prototype. CORE-11360 svn path=/trunk/; revision=71507 --- reactos/dll/ntdll/include/ntdllp.h | 1 - reactos/dll/ntdll/ldr/ldrpe.c | 54 ++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/reactos/dll/ntdll/include/ntdllp.h b/reactos/dll/ntdll/include/ntdllp.h index fa7bcfd45d0..2363ae9d92b 100644 --- a/reactos/dll/ntdll/include/ntdllp.h +++ b/reactos/dll/ntdll/include/ntdllp.h @@ -155,7 +155,6 @@ NTSTATUS NTAPI LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL, IN LPSTR ImportName, - IN PVOID DllBase, OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry, OUT PBOOLEAN Existing); diff --git a/reactos/dll/ntdll/ldr/ldrpe.c b/reactos/dll/ntdll/ldr/ldrpe.c index d022363d815..a93ca3f56f2 100644 --- a/reactos/dll/ntdll/ldr/ldrpe.c +++ b/reactos/dll/ntdll/ldr/ldrpe.c @@ -297,7 +297,6 @@ LdrpHandleOneNewFormatImportDescriptor(IN LPWSTR DllPath OPTIONAL, /* Load the module for this entry */ Status = LdrpLoadImportModule(DllPath, BoundImportName, - LdrEntry->DllBase, &DllLdrEntry, &AlreadyLoaded); if (!NT_SUCCESS(Status)) @@ -371,7 +370,6 @@ LdrpHandleOneNewFormatImportDescriptor(IN LPWSTR DllPath OPTIONAL, /* Load the module */ Status = LdrpLoadImportModule(DllPath, ForwarderName, - LdrEntry->DllBase, &ForwarderLdrEntry, &AlreadyLoaded); if (NT_SUCCESS(Status)) @@ -558,7 +556,6 @@ LdrpHandleOneOldFormatImportDescriptor(IN LPWSTR DllPath OPTIONAL, /* Load the module associated to it */ Status = LdrpLoadImportModule(DllPath, ImportName, - LdrEntry->DllBase, &DllLdrEntry, &AlreadyLoaded); if (!NT_SUCCESS(Status)) @@ -818,22 +815,24 @@ LdrpWalkImportDescriptor(IN LPWSTR DllPath OPTIONAL, return Status; } -/* FIXME: This function is missing SxS support and has wrong prototype */ +/* FIXME: This function is missing SxS support */ NTSTATUS NTAPI LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL, IN LPSTR ImportName, - IN PVOID DllBase, OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry, OUT PBOOLEAN Existing) { ANSI_STRING AnsiString; PUNICODE_STRING ImpDescName; + const WCHAR *p; + BOOLEAN GotExtension; + WCHAR c; NTSTATUS Status; PPEB Peb = RtlGetCurrentPeb(); PTEB Teb = NtCurrentTeb(); - DPRINT("LdrpLoadImportModule('%s' %p %p %p '%S')\n", ImportName, DllBase, DataTableEntry, Existing, DllPath); + DPRINT("LdrpLoadImportModule('%S' '%s' %p %p)\n", DllPath, ImportName, DataTableEntry, Existing); /* Convert import descriptor name to unicode string */ ImpDescName = &Teb->StaticUnicodeString; @@ -841,6 +840,49 @@ LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL, Status = RtlAnsiStringToUnicodeString(ImpDescName, &AnsiString, FALSE); if (!NT_SUCCESS(Status)) return Status; + /* Find the extension, if present */ + p = ImpDescName->Buffer + ImpDescName->Length / sizeof(WCHAR) - 1; + GotExtension = FALSE; + while (p >= ImpDescName->Buffer) + { + c = *p--; + if (c == L'.') + { + GotExtension = TRUE; + break; + } + else if (c == L'\\') + { + break; + } + } + + /* If no extension was found, add the default extension */ + if (!GotExtension) + { + /* Check that we have space to add one */ + if ((ImpDescName->Length + LdrApiDefaultExtension.Length + sizeof(UNICODE_NULL)) >= + sizeof(Teb->StaticUnicodeBuffer)) + { + /* No space to add the extension */ + DbgPrintEx(DPFLTR_LDR_ID, + DPFLTR_ERROR_LEVEL, + "LDR: %s - Dll name missing extension; with extension " + "added the name is too long\n" + " ImpDescName: (@ %p) \"%wZ\"\n" + " ImpDescName->Length: %u\n", + __FUNCTION__, + ImpDescName, + ImpDescName, + ImpDescName->Length); + return STATUS_NAME_TOO_LONG; + } + + /* Add it. Needs to be null terminated, thus the length check above */ + (VOID)RtlAppendUnicodeStringToString(ImpDescName, + &LdrApiDefaultExtension); + } + /* Check if it's loaded */ if (LdrpCheckForLoadedDll(DllPath, ImpDescName,