[LDR] Don't dereference a possible nullptr on a malformed forwarded import

This commit is contained in:
Mark Jansen 2018-12-28 19:26:32 +01:00
parent 97d0595bf6
commit 3e9cf62470
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B

View file

@ -962,7 +962,7 @@ LdrpSnapThunk(IN PVOID ExportBase,
PIMAGE_IMPORT_BY_NAME AddressOfData; PIMAGE_IMPORT_BY_NAME AddressOfData;
PULONG NameTable; PULONG NameTable;
PUSHORT OrdinalTable; PUSHORT OrdinalTable;
LPSTR ImportName = NULL; LPSTR ImportName = NULL, DotPosition;
USHORT Hint; USHORT Hint;
NTSTATUS Status; NTSTATUS Status;
ULONG_PTR HardErrorParameters[3]; ULONG_PTR HardErrorParameters[3];
@ -1117,8 +1117,14 @@ FailurePath:
{ {
/* Get the Import and Forwarder Names */ /* Get the Import and Forwarder Names */
ImportName = (LPSTR)Thunk->u1.Function; ImportName = (LPSTR)Thunk->u1.Function;
DotPosition = strchr(ImportName, '.');
ASSERT(DotPosition != NULL);
if (!DotPosition)
goto FailurePath;
ForwarderName.Buffer = ImportName; ForwarderName.Buffer = ImportName;
ForwarderName.Length = (USHORT)(strchr(ImportName, '.') - ImportName); ForwarderName.Length = (USHORT)(DotPosition - ImportName);
ForwarderName.MaximumLength = ForwarderName.Length; ForwarderName.MaximumLength = ForwarderName.Length;
Status = RtlAnsiStringToUnicodeString(&TempUString, Status = RtlAnsiStringToUnicodeString(&TempUString,
&ForwarderName, &ForwarderName,