* hookapi.cc (hook_or_detect_cygwin): Change condition when to use
importRVAMaxSize or importRVASize for the mapping size. Make sure to map never more than the section size. Change comments accordingly.
This commit is contained in:
parent
d098f404d4
commit
b732246b87
@ -1,3 +1,9 @@
|
|||||||
|
2012-03-13 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* hookapi.cc (hook_or_detect_cygwin): Change condition when to use
|
||||||
|
importRVAMaxSize or importRVASize for the mapping size. Make sure
|
||||||
|
to map never more than the section size. Change comments accordingly.
|
||||||
|
|
||||||
2012-03-13 Corinna Vinschen <corinna@vinschen.de>
|
2012-03-13 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* include/netdb.h (h_errno): Add self-referencing macro and comment.
|
* include/netdb.h (h_errno): Add self-referencing macro and comment.
|
||||||
|
@ -310,12 +310,14 @@ hook_or_detect_cygwin (const char *name, const void *fn, WORD& subsys, HANDLE h)
|
|||||||
built with Visual Studio. When built with gcc, importRVASize contains
|
built with Visual Studio. When built with gcc, importRVASize contains
|
||||||
the size of the import RVA table plus the size of the referenced
|
the size of the import RVA table plus the size of the referenced
|
||||||
string table with the DLL names. When built with VS, it only contains
|
string table with the DLL names. When built with VS, it only contains
|
||||||
the size of the naked import RVA table. importRVAMaxSize contains the
|
the size of the naked import RVA table. The following code handles
|
||||||
size of the reminder of the section. If that's less than 64K, we're
|
the situation. importRVAMaxSize contains the size of the remainder
|
||||||
good. Otherwise the executable is potentially *very* big. In that
|
of the section. If the difference between importRVAMaxSize and
|
||||||
case we only map the naked import RVA table and ... */
|
importRVASize is less than 64K, we just use importRVAMaxSize to
|
||||||
|
compute the size of the memory map. Otherwise the executable may be
|
||||||
|
very big. In that case we only map the import RVA table and ... */
|
||||||
DWORD size = importRVA - offset
|
DWORD size = importRVA - offset
|
||||||
+ ((importRVA - offset + importRVAMaxSize
|
+ ((importRVAMaxSize - importRVASize
|
||||||
<= wincap.allocation_granularity ())
|
<= wincap.allocation_granularity ())
|
||||||
? importRVAMaxSize : importRVASize);
|
? importRVAMaxSize : importRVASize);
|
||||||
map = (char *) MapViewOfFile (h, FILE_MAP_READ, 0, offset, size);
|
map = (char *) MapViewOfFile (h, FILE_MAP_READ, 0, offset, size);
|
||||||
@ -323,18 +325,18 @@ hook_or_detect_cygwin (const char *name, const void *fn, WORD& subsys, HANDLE h)
|
|||||||
return NULL;
|
return NULL;
|
||||||
pdfirst = rva (PIMAGE_IMPORT_DESCRIPTOR, map, importRVA - offset);
|
pdfirst = rva (PIMAGE_IMPORT_DESCRIPTOR, map, importRVA - offset);
|
||||||
/* ... carefully check the required size to fit the string table into
|
/* ... carefully check the required size to fit the string table into
|
||||||
the map as well. Allow NAME_MAX bytes for the DLL name. There's a
|
the map as well. Allow NAME_MAX bytes for the DLL name, but don't
|
||||||
slim chance that the allocation will fail, if the string table is
|
go beyond the remainder of the section. */
|
||||||
right at the end of the last section in the file, but that's very
|
if (importRVAMaxSize - importRVASize > wincap.allocation_granularity ())
|
||||||
unlikely. */
|
|
||||||
if (importRVA - offset + importRVAMaxSize > wincap.allocation_granularity ())
|
|
||||||
{
|
{
|
||||||
DWORD newsize = size;
|
DWORD newsize = size;
|
||||||
for (PIMAGE_IMPORT_DESCRIPTOR pd = pdfirst; pd->FirstThunk; pd++)
|
for (PIMAGE_IMPORT_DESCRIPTOR pd = pdfirst; pd->FirstThunk; pd++)
|
||||||
if (pd->Name - delta - offset + (NAME_MAX + 1) > newsize)
|
if (pd->Name - delta - offset + (NAME_MAX + 1) > newsize)
|
||||||
newsize = pd->Name - delta - offset + (NAME_MAX + 1);
|
newsize = pd->Name - delta - offset + (NAME_MAX + 1);
|
||||||
if (newsize > size )
|
if (newsize > size)
|
||||||
{
|
{
|
||||||
|
if (newsize > importRVA - offset + importRVAMaxSize)
|
||||||
|
newsize = importRVA - offset + importRVAMaxSize;
|
||||||
UnmapViewOfFile (map);
|
UnmapViewOfFile (map);
|
||||||
map = (char *) MapViewOfFile (h, FILE_MAP_READ, 0, offset,
|
map = (char *) MapViewOfFile (h, FILE_MAP_READ, 0, offset,
|
||||||
newsize);
|
newsize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user