PE loader: corrected an assertion (fixes bug reported by GvG), added a
sanity check, return STATUS_INVALID_IMAGE_PROTECT in case of
unrecognized PE signature (to match Windows behavior), removed evil
STATUS_UNSUCCESSFUL, corrected successful return code
Memory manager: return STATUS_INVALID_IMAGE_NOT_MZ when no loader
accepts the format (to match Windows behavior)
Modified: trunk/reactos/ntoskrnl/mm/pe.c
Modified: trunk/reactos/ntoskrnl/mm/section.c
_____
Modified: trunk/reactos/ntoskrnl/mm/pe.c
--- trunk/reactos/ntoskrnl/mm/pe.c 2005-07-08 12:16:47 UTC (rev
16509)
+++ trunk/reactos/ntoskrnl/mm/pe.c 2005-07-08 16:37:07 UTC (rev
16510)
@@ -216,7 +216,7 @@
ASSERT(Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize));
- ASSERT(FileHeaderSize >= sizeof(IMAGE_DOS_HEADER));
+ ASSERT(EXEFMT_LOAD_HEADER_SIZE >= sizeof(IMAGE_DOS_HEADER));
ASSERT(((UINT_PTR)FileHeader % TYPE_ALIGNMENT(IMAGE_DOS_HEADER)) ==
0);
#define DIE(ARGS_) { DPRINT ARGS_; goto l_Return; }
@@ -227,6 +227,10 @@
/* DOS HEADER */
nStatus = STATUS_ROS_EXEFMT_UNKNOWN_FORMAT;
+ /* image too small to be an MZ executable */
+ if(FileHeaderSize < sizeof(IMAGE_DOS_HEADER))
+ DIE(("Too small to be an MZ executable, size is %lu\n",
FileHeaderSize));
+
/* no MZ signature */
if(pidhDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
DIE(("No MZ signature found, e_magic is %hX\n",
pidhDosHeader->e_magic));
@@ -310,14 +314,16 @@
}
/* invalid NT header */
+ nStatus = STATUS_INVALID_IMAGE_PROTECT;
+
if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE)
DIE(("The file isn't a PE executable, Signature is %X\n",
pinhNtHeader->Signature));
+ nStatus = STATUS_INVALID_IMAGE_FORMAT;
+
if(!Intsafe_AddULong32(&cbNtHeaderSize,
pinhNtHeader->FileHeader.SizeOfOptionalHeader,
FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
DIE(("The full NT header is too large\n"));
- nStatus = STATUS_UNSUCCESSFUL;
-
/* the buffer doesn't contain the whole NT header */
if(cbReadSize < cbNtHeaderSize)
DIE(("The file doesn't contain the full NT header\n"));
@@ -721,7 +727,7 @@
*Flags |= EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED;
/* Success */
- nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT & EXEFMT_LOADED_PE32;
+ nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT | EXEFMT_LOADED_PE32;
l_Return:
if(pBuffer)
_____
Modified: trunk/reactos/ntoskrnl/mm/section.c
--- trunk/reactos/ntoskrnl/mm/section.c 2005-07-08 12:16:47 UTC (rev
16509)
+++ trunk/reactos/ntoskrnl/mm/section.c 2005-07-08 16:37:07 UTC (rev
16510)
@@ -3039,7 +3039,7 @@
*/
if (Status == STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
{
- Status = STATUS_INVALID_IMAGE_FORMAT;
+ Status = STATUS_INVALID_IMAGE_NOT_MZ;
ASSERT(!NT_SUCCESS(Status));
}
Show replies by date