Commit 4fe419cac3a5732844e5dd9fd52600b054bd0b18

Pali Rohár 2019-05-23T20:23:33

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.

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 );
     }