From 0b592aeef28a5942322ea353096b85d0e8600459 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 30 May 2012 14:37:53 +0000 Subject: [PATCH] * hookapi.cc (find_first_notloaded_dll): Extend comment. Fix usage of mapped memory. Shorten static library name buffer to MAX_PATH. Use strlcpy to copy library name to buffer. Only Unmap "map" if it has been Mapped before. * pinfo.cc (status_exit): Drop unneeded declaration of find_first_notloaded_dll in favor of the declaration in winsup.h. --- winsup/cygwin/ChangeLog | 9 +++++++++ winsup/cygwin/hookapi.cc | 22 ++++++++++++++-------- winsup/cygwin/pinfo.cc | 1 - 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index bfb69ab9e..38f3a3a53 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2012-05-30 Corinna Vinschen + + * hookapi.cc (find_first_notloaded_dll): Extend comment. Fix usage of + mapped memory. Shorten static library name buffer to MAX_PATH. Use + strlcpy to copy library name to buffer. Only Unmap "map" if it has been + Mapped before. + * pinfo.cc (status_exit): Drop unneeded declaration of + find_first_notloaded_dll in favor of the declaration in winsup.h. + 2012-05-30 Corinna Vinschen * thread.cc: Remove temporary newlib workaround, now that newlib diff --git a/winsup/cygwin/hookapi.cc b/winsup/cygwin/hookapi.cc index ba9d55112..8a9a2bfdd 100644 --- a/winsup/cygwin/hookapi.cc +++ b/winsup/cygwin/hookapi.cc @@ -165,7 +165,8 @@ makename (const char *name, char *&buf, int& i, int inc) /* Find first missing dll in a given executable. FIXME: This is not foolproof since it doesn't look for dlls in the same directory as the given executable, like Windows. Instead it - searches for dlls in the context of the current executable. */ + searches for dlls in the context of the current executable. + It also only finds direct dependencies, not indirect ones. */ const char * find_first_notloaded_dll (path_conv& pc) { @@ -226,32 +227,37 @@ find_first_notloaded_dll (path_conv& pc) importRVA -= delta; DWORD offset = 0; - char *map = NULL; + HMODULE map = NULL; if (importRVA + importRVAMaxSize > wincap.allocation_granularity ()) { offset = rounddown (importRVA, wincap.allocation_granularity ()); DWORD size = importRVA - offset + importRVAMaxSize; - map = (char *) MapViewOfFile (hc, FILE_MAP_READ, 0, offset, size); + map = (HMODULE) MapViewOfFile (hc, FILE_MAP_READ, 0, + offset, size); if (!map) goto out; } // Convert imports RVA to a usable pointer PIMAGE_IMPORT_DESCRIPTOR pdfirst; - pdfirst = rva (PIMAGE_IMPORT_DESCRIPTOR, hm, importRVA - offset); + pdfirst = rva (PIMAGE_IMPORT_DESCRIPTOR, map ?: hm, + importRVA - offset); // Iterate through each import descriptor, and redirect if appropriate for (PIMAGE_IMPORT_DESCRIPTOR pd = pdfirst; pd->FirstThunk; pd++) { - const char *lib = rva (PSTR, hm, pd->Name - delta - offset); + const char *lib = rva (PSTR, map ?: hm, + pd->Name - delta - offset); if (!LoadLibraryEx (lib, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE)) { - static char buf[NT_MAX_PATH]; - res = strcpy (buf, lib); + static char buf[MAX_PATH]; + strlcpy (buf, lib, MAX_PATH); + res = buf; } } - UnmapViewOfFile (map); + if (map) + UnmapViewOfFile (map); } } diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index fda0abc9a..c9a7b413e 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -114,7 +114,6 @@ pinfo_init (char **envp, int envc) static DWORD status_exit (DWORD x) { - const char *find_first_notloaded_dll (path_conv &); switch (x) { case STATUS_DLL_NOT_FOUND: