mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
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) svn path=/trunk/; revision=16510
This commit is contained in:
parent
622c4d86e9
commit
4c9e39ee83
2 changed files with 11 additions and 5 deletions
|
@ -216,7 +216,7 @@ NTSTATUS NTAPI PeFmtCreateSection
|
|||
|
||||
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 @@ NTSTATUS NTAPI PeFmtCreateSection
|
|||
/* 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 @@ l_ReadHeaderFromFile:
|
|||
}
|
||||
|
||||
/* 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 @@ l_ReadHeaderFromFile:
|
|||
*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)
|
||||
|
|
|
@ -3039,7 +3039,7 @@ ExeFmtpCreateImageSection(HANDLE FileHandle,
|
|||
*/
|
||||
if (Status == STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
|
||||
{
|
||||
Status = STATUS_INVALID_IMAGE_FORMAT;
|
||||
Status = STATUS_INVALID_IMAGE_NOT_MZ;
|
||||
ASSERT(!NT_SUCCESS(Status));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue