Commit fdd66643 authored by Alexandre Julliard's avatar Alexandre Julliard

Make sure the import directory is not in shared memory.

parent 34372dcb
......@@ -502,6 +502,7 @@ static LPVOID map_image( HANDLE hmapping, int fd, char *base, DWORD total_size,
IMAGE_DOS_HEADER *dos;
IMAGE_NT_HEADERS *nt;
IMAGE_SECTION_HEADER *sec;
IMAGE_DATA_DIRECTORY *imports;
int i, pos;
DWORD err = GetLastError();
FILE_VIEW *view;
......@@ -536,6 +537,9 @@ static LPVOID map_image( HANDLE hmapping, int fd, char *base, DWORD total_size,
sec = (IMAGE_SECTION_HEADER*)((char*)&nt->OptionalHeader+nt->FileHeader.SizeOfOptionalHeader);
if ((char *)(sec + nt->FileHeader.NumberOfSections) > ptr + header_size) goto error;
imports = nt->OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_IMPORT;
if (!imports->Size || !imports->VirtualAddress) imports = NULL;
/* check the architecture */
if (nt->FileHeader.Machine != IMAGE_FILE_MACHINE_I386)
......@@ -595,6 +599,19 @@ static LPVOID map_image( HANDLE hmapping, int fd, char *base, DWORD total_size,
ERR_(module)( "Could not map shared section %.8s\n", sec->Name );
goto error;
}
/* check if the import directory falls inside this section */
if (imports && imports->VirtualAddress >= sec->VirtualAddress &&
imports->VirtualAddress < sec->VirtualAddress + size)
{
DWORD base = imports->VirtualAddress & ~page_mask;
DWORD end = imports->VirtualAddress + ROUND_SIZE( imports->VirtualAddress,
imports->Size );
if (end > sec->VirtualAddress + size) end = sec->VirtualAddress + size;
if (end > base) VIRTUAL_mmap( shared_fd, ptr + base, end - base,
pos, 0, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED, NULL );
}
pos += size;
continue;
}
......
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