kernel32: Prevent second loading of a library with specified path.

Alexander Morozov amorozov at etersoft.ru
Thu Jun 4 08:06:11 CDT 2009


Changelog
	Prevent second loading of a library with specified path

This patch fixes bug #18775. I tested WinXP and Win2003.

When a library have long name (> 8 symbols before extension) an application
can run LoadLibrary(long name) and later LoadLibrary(8.3 name).
In some cases Windows will load image second time, in other it will return
pointer to already loaded image.
I found that Windows does not load library second time in these cases:
1) c:\dir\libliblib.dll and c:\dir\LIBLIB~1.DLL
2) \dir\libliblib.dll and \dir\LIBLIB~1.DLL
3) .\libliblib.dll and .\LIBLIB~1.DLL
4) dir\libliblib.dll and dir\LIBLIB~1.DLL
and load it in cases:
5) libliblib.dll and LIBLIB~1.DLL
6) c:libliblib.dll and c:LIBLIB~1.DLL
-------------- next part --------------
From 96c1eddca96cda14a9b7dfd06dd6f1951f54136b Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov at etersoft.ru>
Date: Thu, 4 Jun 2009 16:36:42 +0400
Subject: [PATCH] kernel32: Prevent second loading of a library with specified path.

---
 dlls/kernel32/module.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c
index 86675b6..ea2b9cf 100644
--- a/dlls/kernel32/module.c
+++ b/dlls/kernel32/module.c
@@ -921,12 +921,30 @@ HMODULE WINAPI LoadLibraryExW(LPCWSTR libnameW, HANDLE hfile, DWORD flags)
 {
     UNICODE_STRING      wstr;
     HMODULE             res;
+    WCHAR              *pathnameW;
+    DWORD               len;
 
     if (!libnameW)
     {
         SetLastError(ERROR_INVALID_PARAMETER);
         return 0;
     }
+
+    /* Prevent second loading of a library with specified path */
+    if (strchrW( libnameW, '\\' ) && (len = GetLongPathNameW( libnameW, NULL, 0 )))
+    {
+        if (!(pathnameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
+        {
+            SetLastError( ERROR_NOT_ENOUGH_MEMORY );
+            return 0;
+        }
+        GetLongPathNameW( libnameW, pathnameW, len );
+        RtlInitUnicodeString( &wstr, pathnameW );
+        res = load_library( &wstr, flags );
+        HeapFree( GetProcessHeap(), 0, pathnameW );
+        return res;
+    }
+
     RtlInitUnicodeString( &wstr, libnameW );
     if (wstr.Buffer[wstr.Length/sizeof(WCHAR) - 1] != ' ')
         return load_library( &wstr, flags );
-- 
1.6.3.1



More information about the wine-patches mailing list