From 24386abb3b6c2e509a43a537e35e9600dd25d2ed Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 2 Sep 2010 18:38:06 +0300 Subject: [PATCH] Increase safety on Windows Call SetDllDirectory() to reduce risk of DLL hijacking, and call SetProcessDEPPolicy() to reduce risk of rogue code execution. --- app/main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/main.c b/app/main.c index 2fa9c19e19..aaa8ea760e 100644 --- a/app/main.c +++ b/app/main.c @@ -60,6 +60,10 @@ #include "version.h" #ifdef G_OS_WIN32 +/* To get PROCESS_DEP_* defined we need _WIN32_WINNT at 0x0601. We still + * use the API optionally only if present, though. + */ +#define _WIN32_WINNT 0x0601 #include #include #endif @@ -279,6 +283,30 @@ main (int argc, argv = __argv; #endif +#ifdef G_OS_WIN32 + /* Reduce risks */ + { + typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName); + t_SetDllDirectoryA p_SetDllDirectoryA; + + p_SetDllDirectoryA = GetProcAddress (GetModuleHandle ("kernel32.dll"), + "SetDllDirectoryA"); + if (p_SetDllDirectoryA) + (*p_SetDllDirectoryA) (""); + } +#ifndef _WIN64 + { + typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags); + t_SetProcessDEPPolicy p_SetProcessDEPPolicy; + + p_SetProcessDEPPolicy = GetProcAddress (GetModuleHandle ("kernel32.dll"), + "SetProcessDEPPolicy"); + if (p_SetProcessDEPPolicy) + (*p_SetProcessDEPPolicy) (PROCESS_DEP_ENABLE|PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION); + } +#endif +#endif + g_thread_init (NULL); #ifdef GIMP_UNSTABLE