Commit 4d417076 authored by Alexandre Julliard's avatar Alexandre Julliard

server: Don't zero out the PE optional header regardless of specified size.

parent 316b5bc9
...@@ -144,13 +144,13 @@ static const IMAGE_NT_HEADERS nt_header_template = ...@@ -144,13 +144,13 @@ static const IMAGE_NT_HEADERS nt_header_template =
sizeof(dos_header) + sizeof(nt_header_template), /* SizeOfHeaders */ sizeof(dos_header) + sizeof(nt_header_template), /* SizeOfHeaders */
0, /* CheckSum */ 0, /* CheckSum */
IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */ IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
0, /* DllCharacteristics */ IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE | IMAGE_DLLCHARACTERISTICS_NX_COMPAT, /* DllCharacteristics */
0, /* SizeOfStackReserve */ 0x100000, /* SizeOfStackReserve */
0, /* SizeOfStackCommit */ 0x1000, /* SizeOfStackCommit */
0, /* SizeOfHeapReserve */ 0x100000, /* SizeOfHeapReserve */
0, /* SizeOfHeapCommit */ 0x1000, /* SizeOfHeapCommit */
0, /* LoaderFlags */ 0, /* LoaderFlags */
0, /* NumberOfRvaAndSizes */ IMAGE_NUMBEROF_DIRECTORY_ENTRIES, /* NumberOfRvaAndSizes */
{ { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */ { { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
} }
}; };
...@@ -401,7 +401,6 @@ static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HE ...@@ -401,7 +401,6 @@ static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HE
"%u: MaximumStackSize wrong %Ix / %Ix\n", id, image.MaximumStackSize, max_stack ); "%u: MaximumStackSize wrong %Ix / %Ix\n", id, image.MaximumStackSize, max_stack );
ok( image.CommittedStackSize == commit_stack, ok( image.CommittedStackSize == commit_stack,
"%u: CommittedStackSize wrong %Ix / %Ix\n", id, image.CommittedStackSize, commit_stack ); "%u: CommittedStackSize wrong %Ix / %Ix\n", id, image.CommittedStackSize, commit_stack );
todo_wine_if( truncated )
ok( image.SubSystemType == nt_header->OptionalHeader.Subsystem, ok( image.SubSystemType == nt_header->OptionalHeader.Subsystem,
"%u: SubSystemType wrong %08lx / %08x\n", id, "%u: SubSystemType wrong %08lx / %08x\n", id,
image.SubSystemType, nt_header->OptionalHeader.Subsystem ); image.SubSystemType, nt_header->OptionalHeader.Subsystem );
...@@ -481,7 +480,7 @@ static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HE ...@@ -481,7 +480,7 @@ static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HE
if (!(nt_header->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE)) if (!(nt_header->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE))
ok( !image.ImageDynamicallyRelocated || broken( image.ComPlusILOnly ), /* <= win7 */ ok( !image.ImageDynamicallyRelocated || broken( image.ComPlusILOnly ), /* <= win7 */
"%u: wrong ImageDynamicallyRelocated flags %02x\n", id, image.ImageFlags ); "%u: wrong ImageDynamicallyRelocated flags %02x\n", id, image.ImageFlags );
else if (image.ImageContainsCode && !cor_header) else if (image.ImageContainsCode && !image.ImageMappedFlat && !cor_header)
ok( image.ImageDynamicallyRelocated, ok( image.ImageDynamicallyRelocated,
"%u: wrong ImageDynamicallyRelocated flags %02x\n", id, image.ImageFlags ); "%u: wrong ImageDynamicallyRelocated flags %02x\n", id, image.ImageFlags );
else else
...@@ -866,7 +865,7 @@ static void test_Loader(void) ...@@ -866,7 +865,7 @@ static void test_Loader(void)
{ 0x04, { 0x04,
0, 0x08, 0, 0x08,
0x04 /* also serves as e_lfanew in the truncated MZ header */, 0x04, 0x04 /* also serves as e_lfanew in the truncated MZ header */, 0x04,
0x200000, 0x2000,
0x40, 0x40,
{ ERROR_SUCCESS } { ERROR_SUCCESS }
} }
......
...@@ -695,8 +695,8 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -695,8 +695,8 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
} opt; } opt;
} nt; } nt;
off_t pos; off_t pos;
int size, opt_size; int size;
size_t mz_size, clr_va, clr_size; size_t mz_size, clr_va = 0, clr_size = 0;
unsigned int i; unsigned int i;
/* load the headers */ /* load the headers */
...@@ -710,9 +710,6 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -710,9 +710,6 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
size = pread( unix_fd, &nt, sizeof(nt), pos ); size = pread( unix_fd, &nt, sizeof(nt), pos );
if (size < sizeof(nt.Signature) + sizeof(nt.FileHeader)) return STATUS_INVALID_IMAGE_PROTECT; if (size < sizeof(nt.Signature) + sizeof(nt.FileHeader)) return STATUS_INVALID_IMAGE_PROTECT;
/* zero out Optional header in the case it's not present or partial */
opt_size = max( nt.FileHeader.SizeOfOptionalHeader, offsetof( IMAGE_OPTIONAL_HEADER32, CheckSum ));
size = min( size, sizeof(nt.Signature) + sizeof(nt.FileHeader) + opt_size );
if (size < sizeof(nt)) memset( (char *)&nt + size, 0, sizeof(nt) - size ); if (size < sizeof(nt)) memset( (char *)&nt + size, 0, sizeof(nt) - size );
if (nt.Signature != IMAGE_NT_SIGNATURE) if (nt.Signature != IMAGE_NT_SIGNATURE)
{ {
...@@ -729,9 +726,11 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -729,9 +726,11 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
if (!is_machine_32bit( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; if (!is_machine_32bit( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT;
if (!is_machine_supported( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; if (!is_machine_supported( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT;
clr_va = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; if (nt.opt.hdr32.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR)
clr_size = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size; {
clr_va = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
clr_size = nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size;
}
mapping->image.base = nt.opt.hdr32.ImageBase; mapping->image.base = nt.opt.hdr32.ImageBase;
mapping->image.entry_point = nt.opt.hdr32.AddressOfEntryPoint; mapping->image.entry_point = nt.opt.hdr32.AddressOfEntryPoint;
mapping->image.map_size = ROUND_SIZE( nt.opt.hdr32.SizeOfImage ); mapping->image.map_size = ROUND_SIZE( nt.opt.hdr32.SizeOfImage );
...@@ -751,7 +750,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -751,7 +750,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
mapping->image.image_flags = 0; mapping->image.image_flags = 0;
if (nt.opt.hdr32.SectionAlignment & page_mask) if (nt.opt.hdr32.SectionAlignment & page_mask)
mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat; mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat;
if ((nt.opt.hdr32.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) && else if ((nt.opt.hdr32.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) &&
mapping->image.contains_code && !(clr_va && clr_size)) mapping->image.contains_code && !(clr_va && clr_size))
mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated; mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated;
break; break;
...@@ -761,9 +760,11 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -761,9 +760,11 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
if (!is_machine_64bit( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; if (!is_machine_64bit( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT;
if (!is_machine_supported( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT; if (!is_machine_supported( nt.FileHeader.Machine )) return STATUS_INVALID_IMAGE_FORMAT;
clr_va = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; if (nt.opt.hdr64.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR)
clr_size = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size; {
clr_va = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
clr_size = nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size;
}
mapping->image.base = nt.opt.hdr64.ImageBase; mapping->image.base = nt.opt.hdr64.ImageBase;
mapping->image.entry_point = nt.opt.hdr64.AddressOfEntryPoint; mapping->image.entry_point = nt.opt.hdr64.AddressOfEntryPoint;
mapping->image.map_size = ROUND_SIZE( nt.opt.hdr64.SizeOfImage ); mapping->image.map_size = ROUND_SIZE( nt.opt.hdr64.SizeOfImage );
...@@ -783,7 +784,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -783,7 +784,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
mapping->image.image_flags = 0; mapping->image.image_flags = 0;
if (nt.opt.hdr64.SectionAlignment & page_mask) if (nt.opt.hdr64.SectionAlignment & page_mask)
mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat; mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat;
if ((nt.opt.hdr64.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) && else if ((nt.opt.hdr64.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) &&
mapping->image.contains_code && !(clr_va && clr_size)) mapping->image.contains_code && !(clr_va && clr_size))
mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated; mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment