[NTDLL]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 22 Dec 2010 16:19:40 +0000 (16:19 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 22 Dec 2010 16:19:40 +0000 (16:19 +0000)
Raise harderror and terminate process when the image is of a foreign architecture.

svn path=/trunk/; revision=50099

reactos/dll/ntdll/ldr/startup.c

index 83cea30..49f132e 100644 (file)
@@ -330,6 +330,7 @@ LdrpInit2(PCONTEXT Context,
     SYSTEM_BASIC_INFORMATION SystemInformation;
     NTSTATUS Status;
     PVOID BaseAddress = SystemArgument1;
     SYSTEM_BASIC_INFORMATION SystemInformation;
     NTSTATUS Status;
     PVOID BaseAddress = SystemArgument1;
+    ULONG ErrorResponse;
 
     DPRINT("LdrpInit()\n");
     DPRINT("Peb %p\n", Peb);
 
     DPRINT("LdrpInit()\n");
     DPRINT("Peb %p\n", Peb);
@@ -344,16 +345,25 @@ LdrpInit2(PCONTEXT Context,
 
     /*  If MZ header exists  */
     PEDosHeader = (PIMAGE_DOS_HEADER) ImageBase;
 
     /*  If MZ header exists  */
     PEDosHeader = (PIMAGE_DOS_HEADER) ImageBase;
+    NTHeaders = (PIMAGE_NT_HEADERS)((ULONG_PTR)ImageBase + PEDosHeader->e_lfanew);
     DPRINT("PEDosHeader %p\n", PEDosHeader);
 
     if (PEDosHeader->e_magic != IMAGE_DOS_SIGNATURE ||
         PEDosHeader->e_lfanew == 0L ||
     DPRINT("PEDosHeader %p\n", PEDosHeader);
 
     if (PEDosHeader->e_magic != IMAGE_DOS_SIGNATURE ||
         PEDosHeader->e_lfanew == 0L ||
-        *(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)
+        NTHeaders->Signature != IMAGE_NT_SIGNATURE)
     {
         DPRINT1("Image has bad header\n");
         ZwTerminateProcess(NtCurrentProcess(), STATUS_INVALID_IMAGE_FORMAT);
     }
 
     {
         DPRINT1("Image has bad header\n");
         ZwTerminateProcess(NtCurrentProcess(), STATUS_INVALID_IMAGE_FORMAT);
     }
 
+    if (NTHeaders->FileHeader.Machine != IMAGE_FILE_MACHINE_NATIVE)
+    {
+        DPRINT1("Image is for a foreign architecture (0x%x).\n",
+                NTHeaders->FileHeader.Machine);
+        NtRaiseHardError(STATUS_IMAGE_MACHINE_TYPE_MISMATCH, 0, 0, NULL, OptionOk, &ErrorResponse);
+        ZwTerminateProcess(NtCurrentProcess(), STATUS_IMAGE_MACHINE_TYPE_MISMATCH);
+    }
+
     /* normalize process parameters */
     RtlNormalizeProcessParams(Peb->ProcessParameters);
 
     /* normalize process parameters */
     RtlNormalizeProcessParams(Peb->ProcessParameters);
 
@@ -364,8 +374,6 @@ LdrpInit2(PCONTEXT Context,
                      &NlsTable);
     RtlResetRtlTranslations(&NlsTable);
 
                      &NlsTable);
     RtlResetRtlTranslations(&NlsTable);
 
-    NTHeaders = (PIMAGE_NT_HEADERS)((ULONG_PTR)ImageBase + PEDosHeader->e_lfanew);
-
     /* Get number of processors */
     DPRINT("Here\n");
     Status = ZwQuerySystemInformation(SystemBasicInformation,
     /* Get number of processors */
     DPRINT("Here\n");
     Status = ZwQuerySystemInformation(SystemBasicInformation,