mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +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(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);
|
ASSERT(((UINT_PTR)FileHeader % TYPE_ALIGNMENT(IMAGE_DOS_HEADER)) == 0);
|
||||||
|
|
||||||
#define DIE(ARGS_) { DPRINT ARGS_; goto l_Return; }
|
#define DIE(ARGS_) { DPRINT ARGS_; goto l_Return; }
|
||||||
|
@ -227,6 +227,10 @@ NTSTATUS NTAPI PeFmtCreateSection
|
||||||
/* DOS HEADER */
|
/* DOS HEADER */
|
||||||
nStatus = STATUS_ROS_EXEFMT_UNKNOWN_FORMAT;
|
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 */
|
/* no MZ signature */
|
||||||
if(pidhDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
|
if(pidhDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
|
||||||
DIE(("No MZ signature found, e_magic is %hX\n", pidhDosHeader->e_magic));
|
DIE(("No MZ signature found, e_magic is %hX\n", pidhDosHeader->e_magic));
|
||||||
|
@ -310,14 +314,16 @@ l_ReadHeaderFromFile:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* invalid NT header */
|
/* invalid NT header */
|
||||||
|
nStatus = STATUS_INVALID_IMAGE_PROTECT;
|
||||||
|
|
||||||
if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE)
|
if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE)
|
||||||
DIE(("The file isn't a PE executable, Signature is %X\n", pinhNtHeader->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)))
|
if(!Intsafe_AddULong32(&cbNtHeaderSize, pinhNtHeader->FileHeader.SizeOfOptionalHeader, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
|
||||||
DIE(("The full NT header is too large\n"));
|
DIE(("The full NT header is too large\n"));
|
||||||
|
|
||||||
nStatus = STATUS_UNSUCCESSFUL;
|
|
||||||
|
|
||||||
/* the buffer doesn't contain the whole NT header */
|
/* the buffer doesn't contain the whole NT header */
|
||||||
if(cbReadSize < cbNtHeaderSize)
|
if(cbReadSize < cbNtHeaderSize)
|
||||||
DIE(("The file doesn't contain the full NT header\n"));
|
DIE(("The file doesn't contain the full NT header\n"));
|
||||||
|
@ -721,7 +727,7 @@ l_ReadHeaderFromFile:
|
||||||
*Flags |= EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED;
|
*Flags |= EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED;
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT & EXEFMT_LOADED_PE32;
|
nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT | EXEFMT_LOADED_PE32;
|
||||||
|
|
||||||
l_Return:
|
l_Return:
|
||||||
if(pBuffer)
|
if(pBuffer)
|
||||||
|
|
|
@ -3039,7 +3039,7 @@ ExeFmtpCreateImageSection(HANDLE FileHandle,
|
||||||
*/
|
*/
|
||||||
if (Status == STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
|
if (Status == STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
|
||||||
{
|
{
|
||||||
Status = STATUS_INVALID_IMAGE_FORMAT;
|
Status = STATUS_INVALID_IMAGE_NOT_MZ;
|
||||||
ASSERT(!NT_SUCCESS(Status));
|
ASSERT(!NT_SUCCESS(Status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue