7003962: AWT: securely load DLLs and launch executables using fully qualified path
authordcherepanov
Fri, 08 Apr 2011 16:44:14 +0400
changeset 9834 ce3a106acecd
parent 9833 c974a42c33d6
child 9835 1b8f203cda76
7003962: AWT: securely load DLLs and launch executables using fully qualified path Reviewed-by: art, bae, alanb
jdk/src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp
jdk/src/windows/native/sun/java2d/opengl/OGLFuncs_md.h
jdk/src/windows/native/sun/windows/DllUtil.cpp
jdk/src/windows/native/sun/windows/DllUtil.h
jdk/src/windows/native/sun/windows/ShellFolder2.cpp
jdk/src/windows/native/sun/windows/ThemeReader.cpp
jdk/src/windows/native/sun/windows/awt_Mlib.cpp
jdk/src/windows/native/sun/windows/awt_TextArea.cpp
jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp
jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp
jdk/src/windows/native/sun/windows/stdhdrs.h
--- a/jdk/src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -117,7 +117,7 @@
 {
     typedef IDirect3D9 * WINAPI FnDirect3DCreate9(UINT SDKVersion);
 
-    hLibD3D9 = ::LoadLibrary(TEXT("d3d9.dll"));
+    hLibD3D9 = JDK_LoadSystemLibrary("d3d9.dll");
     if (hLibD3D9 == NULL) {
         J2dRlsTraceLn(J2D_TRACE_ERROR, "InitD3D: no d3d9.dll");
         return E_FAIL;
--- a/jdk/src/windows/native/sun/java2d/opengl/OGLFuncs_md.h	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/java2d/opengl/OGLFuncs_md.h	Fri Apr 08 16:44:14 2011 +0400
@@ -60,7 +60,7 @@
 #define OGL_LIB_IS_UNINITIALIZED() \
     (OGL_LIB_HANDLE == 0)
 #define OGL_OPEN_LIB() \
-    OGL_LIB_HANDLE = LoadLibrary(L"opengl32.dll")
+    OGL_LIB_HANDLE = JDK_LoadSystemLibrary("opengl32.dll")
 #define OGL_CLOSE_LIB() \
     FreeLibrary(OGL_LIB_HANDLE)
 #define OGL_GET_PROC_ADDRESS(f) \
--- a/jdk/src/windows/native/sun/windows/DllUtil.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/DllUtil.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -25,6 +25,7 @@
 
 
 #include "DllUtil.h"
+#include <jdk_util_md.h>
 
 // Disable warning about using this in the initializer list.
 #pragma warning( disable : 4355)
@@ -40,7 +41,7 @@
 HMODULE DllUtil::GetModule()
 {
     if (!module) {
-        module = ::LoadLibrary(name);
+        module = JDK_LoadSystemLibrary(name);
     }
     return module;
 }
@@ -60,7 +61,7 @@
 }
 
 DwmAPI::DwmAPI() :
-    DllUtil(_T("DWMAPI.DLL")),
+    DllUtil("DWMAPI.DLL"),
     DwmIsCompositionEnabledFunction((DllUtil*)this, "DwmIsCompositionEnabled"),
     DwmGetWindowAttributeFunction((DllUtil*)this, "DwmGetWindowAttribute")
 {
--- a/jdk/src/windows/native/sun/windows/DllUtil.h	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/DllUtil.h	Fri Apr 08 16:44:14 2011 +0400
@@ -43,7 +43,7 @@
         FARPROC GetProcAddress(LPCSTR name);
 
     protected:
-        DllUtil(const TCHAR * name) : name(name), module(NULL) {}
+        DllUtil(const char * name) : name(name), module(NULL) {}
         virtual ~DllUtil();
 
         HMODULE GetModule();
@@ -68,7 +68,7 @@
         };
 
     private:
-        const TCHAR * const name;
+        const char * const name;
         HMODULE module;
 };
 
--- a/jdk/src/windows/native/sun/windows/ShellFolder2.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/ShellFolder2.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -120,15 +120,15 @@
         return TRUE;
     }
     // Load libraries
-    libShell32 = LoadLibrary(TEXT("shell32.dll"));
+    libShell32 = JDK_LoadSystemLibrary("shell32.dll");
     if (libShell32 == NULL) {
         return FALSE;
     }
-    libUser32 = LoadLibrary(TEXT("user32.dll"));
+    libUser32 = JDK_LoadSystemLibrary("user32.dll");
     if (libUser32 == NULL) {
         return FALSE;
     }
-    libComCtl32 = LoadLibrary(TEXT("comctl32.dll"));
+    libComCtl32 = JDK_LoadSystemLibrary("comctl32.dll");
     if (libComCtl32 == NULL) {
         return FALSE;
     }
@@ -1021,7 +1021,8 @@
     (JNIEnv* env, jclass cls, jstring libName, jint iconID,
      jint cxDesired, jint cyDesired, jboolean useVGAColors)
 {
-    HINSTANCE libHandle = LoadLibrary(JNU_GetStringPlatformChars(env, libName, NULL));
+    const char *pLibName = env->GetStringUTFChars(libName, NULL);
+    HINSTANCE libHandle = (HINSTANCE)JDK_LoadSystemLibrary(pLibName);
     if (libHandle != NULL) {
         UINT fuLoad = (useVGAColors && !IS_WINXP) ? LR_VGACOLOR : 0;
         return ptr_to_jlong(LoadImage(libHandle, MAKEINTRESOURCE(iconID),
--- a/jdk/src/windows/native/sun/windows/ThemeReader.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/ThemeReader.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -150,7 +150,7 @@
 
 BOOL InitThemes() {
     static HMODULE hModThemes = NULL;
-    hModThemes = LoadLibrary(TEXT("UXTHEME.DLL"));
+    hModThemes = JDK_LoadSystemLibrary("UXTHEME.DLL");
     DTRACE_PRINTLN1("InitThemes hModThemes = %x\n", hModThemes);
     if(hModThemes) {
         DTRACE_PRINTLN("Loaded UxTheme.dll\n");
--- a/jdk/src/windows/native/sun/windows/awt_Mlib.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/awt_Mlib.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -43,12 +43,13 @@
         mlibSysFnS_t tempSysFns;
         mlib_status ret = MLIB_SUCCESS;
 
-        /* Try to load library. Routine should find the library successfully
-         * because this library is already loaded to the process space by
-         * the System.loadLibrary() call. Here we just need to get handle to
-         * initialize the pointers to required mlib routines.
+        /* Try to receive handle for the library. Routine should find
+         * the library successfully because this library is already
+         * loaded to the process space by the System.loadLibrary() call.
+         * Here we just need to get handle to initialize the pointers to
+         * required mlib routines.
          */
-        hDLL = ::LoadLibrary(TEXT("mlib_image.dll"));
+        hDLL = ::GetModuleHandle(TEXT("mlib_image.dll"));
 
         if (hDLL == NULL) {
             return MLIB_FAILURE;
@@ -94,9 +95,6 @@
             i++;
         }
 
-        if (ret != MLIB_SUCCESS) {
-            ::FreeLibrary(hDLL);
-        }
         return ret;
     }
 
--- a/jdk/src/windows/native/sun/windows/awt_TextArea.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/awt_TextArea.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -77,7 +77,7 @@
 LPCTSTR AwtTextArea::GetClassName() {
     static BOOL richedLibraryLoaded = FALSE;
     if (!richedLibraryLoaded) {
-        ::LoadLibrary(TEXT("RICHED20.DLL"));
+        JDK_LoadSystemLibrary("RICHED20.DLL");
         richedLibraryLoaded = TRUE;
     }
     return RICHEDIT_CLASS;
--- a/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -185,7 +185,7 @@
     int shellVersion = 5; // WIN_2000
     // MSDN: DllGetVersion should not be implicitly called, but rather
     // loaded using GetProcAddress
-    HMODULE hShell = LoadLibrary(TEXT("Shell32.dll"));
+    HMODULE hShell = JDK_LoadSystemLibrary("Shell32.dll");
     if (hShell != NULL) {
         DLLGETVERSIONPROC proc = (DLLGETVERSIONPROC)GetProcAddress(hShell, "DllGetVersion");
         if (proc != NULL) {
--- a/jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp	Fri Apr 08 16:44:14 2011 +0400
@@ -63,7 +63,7 @@
 
     bAlreadySet = TRUE;
 
-    HMODULE hLibUser32Dll = ::LoadLibrary(TEXT("user32.dll"));
+    HMODULE hLibUser32Dll = JDK_LoadSystemLibrary("user32.dll");
 
     if (hLibUser32Dll != NULL) {
         SetProcessDPIAwareFunc *lpSetProcessDPIAware =
--- a/jdk/src/windows/native/sun/windows/stdhdrs.h	Tue Apr 05 16:19:37 2011 -0700
+++ b/jdk/src/windows/native/sun/windows/stdhdrs.h	Fri Apr 08 16:44:14 2011 +0400
@@ -47,6 +47,7 @@
 // standard Java headers
 #include <jni.h>
 #include <jni_util.h>
+#include <jdk_util.h>
 
 } // extern "C"