From 4fe419cac3a5732844e5dd9fd52600b054bd0b18 Mon Sep 17 00:00:00 2001 From: Pali Rohár <pali.rohar@gmail.com> Date: Thu, 23 May 2019 20:23:33 +0200 Subject: Correctly process and indicate error in dlsym() function Function save_err_str() checks for error by GetLastError() call. So ensure that last error is always set when error occurs. --- dlfcn.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dlfcn.c b/dlfcn.c index c97a870..26135e3 100644 --- a/dlfcn.c +++ b/dlfcn.c @@ -362,10 +362,17 @@ void *dlsym( void *handle, const char *name ) size_t sLen; sLen = VirtualQueryEx( hCurrentProc, _ReturnAddress(), &info, sizeof( info ) ); if( sLen != sizeof( info ) ) + { + if( sLen != 0 ) + SetLastError( ERROR_INVALID_PARAMETER ); goto end; + } hCaller = (HMODULE) info.AllocationBase; - if(!hCaller) + if( !hCaller ) + { + SetLastError( ERROR_INVALID_PARAMETER ); goto end; + } } if( handle != RTLD_NEXT ) @@ -423,6 +430,8 @@ void *dlsym( void *handle, const char *name ) end: if( symbol == NULL ) { + if( GetLastError() == 0 ) + SetLastError( ERROR_PROC_NOT_FOUND ); save_err_str( name ); } -- cgit v1.2.3-55-g6feb