]> sourceware.org Git - newlib-cygwin.git/commitdiff
* hookapi.cc (hook_or_detect_cygwin): Change condition when to use
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 13 Mar 2012 17:15:28 +0000 (17:15 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 13 Mar 2012 17:15:28 +0000 (17:15 +0000)
importRVAMaxSize or importRVASize for the mapping size.  Make sure
to map never more than the section size.  Change comments accordingly.

winsup/cygwin/ChangeLog
winsup/cygwin/hookapi.cc

index 95ff1a24d888316c7cd636b494b65f457ae71ca0..d0f74cf6150b0d16d513a216ac4510e187e2fca3 100644 (file)
@@ -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>
 
        * include/netdb.h (h_errno): Add self-referencing macro and comment.
index a56538dc63df3a515a07e50769781e29800ccbbe..11280c6a240c821ba917188458a62ce0cacc35f6 100644 (file)
@@ -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
         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
-        the size of the naked import RVA table.  importRVAMaxSize contains the
-        size of the reminder of the section.  If that's less than 64K, we're
-        good.  Otherwise the executable is potentially *very* big.  In that
-        case we only map the naked import RVA table and ... */
+        the size of the naked import RVA table.  The following code handles
+        the situation.  importRVAMaxSize contains the size of the remainder
+        of the section.  If the difference between importRVAMaxSize 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
-                  + ((importRVA - offset + importRVAMaxSize
+                  + ((importRVAMaxSize - importRVASize
                       <= wincap.allocation_granularity ())
                      ? importRVAMaxSize : importRVASize);
       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;
       pdfirst = rva (PIMAGE_IMPORT_DESCRIPTOR, map, importRVA - offset);
       /* ... 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
-        slim chance that the allocation will fail, if the string table is
-        right at the end of the last section in the file, but that's very
-        unlikely. */
-      if (importRVA - offset + importRVAMaxSize > wincap.allocation_granularity ())
+         the map as well.  Allow NAME_MAX bytes for the DLL name, but don't
+        go beyond the remainder of the section. */
+      if (importRVAMaxSize - importRVASize > wincap.allocation_granularity ())
        {
          DWORD newsize = size;
          for (PIMAGE_IMPORT_DESCRIPTOR pd = pdfirst; pd->FirstThunk; pd++)
            if (pd->Name - delta - offset + (NAME_MAX + 1) > newsize)
              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);
              map = (char *) MapViewOfFile (h, FILE_MAP_READ, 0, offset,
                                            newsize);
This page took 0.033827 seconds and 5 git commands to generate.