mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-05 21:42:47 -05:00
Add automatic type-checking to GET_WINDOWS_FUNCTION.
This gives me an extra safety-check against having mistyped one of the function prototypes that we load at run time from DLLs: we verify that the typedef we defined based on the prototype in our source code matches the type of the real function as declared in the Windows headers. This was an idea I had while adding a pile of further functions using this mechanism. It didn't catch any errors (either in the new functions or in the existing collection), but that's no reason not to keep it anyway now that I've thought of it! In VS2015, this automated type-check works for most functions, but a couple manage to break it. SetCurrentProcessExplicitAppUserModelID in winjump.c can't be type-checked, because including <shobjidl.h> where that function is declared would also bring in a load of other stuff that conflicts with the painful manual COM declarations in winjump.c. (That stuff could probably be removed now we're on an up-to-date Visual Studio, on the other hand, but that's a separate chore.) And gai_strerror, used in winnet.c, does _have_ an implementation in a DLL, but the header files like to provide an inline version with a different calling convention, which defeats this error-checking trick. And in the older VS2003 that we still precautionarily build with, several more type-checks have to be #ifdeffed out because the functions they check against just aren't there at all.
This commit is contained in:
@ -177,7 +177,14 @@ void dll_hijacking_protection(void)
|
||||
|
||||
if (!kernel32_module) {
|
||||
kernel32_module = load_system32_dll("kernel32.dll");
|
||||
#if defined _MSC_VER && _MSC_VER < 1900
|
||||
/* For older Visual Studio, this function isn't available in
|
||||
* the header files to type-check */
|
||||
GET_WINDOWS_FUNCTION_NO_TYPECHECK(
|
||||
kernel32_module, SetDefaultDllDirectories);
|
||||
#else
|
||||
GET_WINDOWS_FUNCTION(kernel32_module, SetDefaultDllDirectories);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (p_SetDefaultDllDirectories) {
|
||||
|
Reference in New Issue
Block a user