* loadlib.h: New header implementing safe LoadLibrary calls.

Include throughout files using LoadLibrary function.
	* cygcheck.cc (dump_sysinfo): Retrieve kernel32.dll handle via
	GetModuleHandle, rather than using LoadLibrary.
	* cygpath.cc (get_long_name): Ditto.
	(do_sysfolders): Append .dll suffix in LoadLibrary call.
	* ldh.cc (WinMain): Use LoadLibraryExW with DONT_RESOLVE_DLL_REFERENCES
	to avoid loading malicious library code.
	* locale.cc (print_locale_with_codeset): Change way to retrieve
	kernel32.dll path.
This commit is contained in:
Corinna Vinschen
2010-08-28 11:22:37 +00:00
parent 893a8b78fc
commit 71d8f118da
13 changed files with 95 additions and 15 deletions

View File

@@ -28,6 +28,7 @@ details. */
#include <ddk/winddk.h>
#include <ddk/ntifs.h>
#include "wide_path.h"
#include "loadlib.h"
static const char version[] = "$Revision$";
@@ -452,7 +453,7 @@ get_long_name (const char *filename, DWORD& len)
{
char *sbuf;
wchar_t buf[32768];
static HINSTANCE k32 = LoadLibrary ("kernel32.dll");
static HINSTANCE k32 = GetModuleHandleW (L"kernel32.dll");
static DWORD (WINAPI *GetLongPathName) (LPCWSTR, LPWSTR, DWORD) =
(DWORD (WINAPI *) (LPCWSTR, LPWSTR, DWORD)) GetProcAddress (k32, "GetLongPathNameW");
if (!GetLongPathName)
@@ -610,7 +611,7 @@ do_sysfolders (char option)
break;
case 'H':
k32 = LoadLibrary ("userenv");
k32 = LoadLibrary ("userenv.dll");
if (k32)
GetProfilesDirectoryAPtrW = (BOOL (*) (LPWSTR, LPDWORD))
GetProcAddress (k32, "GetProfilesDirectoryW");