changeset 505:16fbb8d0b834

7016985: (launcher) implement safe secure dll loading Reviewed-by: asaha
author ksrini
date Mon, 07 Mar 2011 08:22:35 -0800
parents 50636a6053f8
children bfc1a4516e20
files src/share/bin/java.c src/share/bin/java.h src/solaris/bin/java_md.c src/windows/bin/java_md.c
diffstat 4 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/bin/java.c	Tue Mar 01 18:14:15 2011 -0800
+++ b/src/share/bin/java.c	Mon Mar 07 08:22:35 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -220,7 +220,8 @@
       }
     }
 
-
+    /* this should be called before anything else */
+    InitLauncher();
 
     /*
      * Make sure the specified version of the JRE is running.
@@ -501,9 +502,9 @@
             const char * format = "Could not find the main class: %s. Program will exit.";
             ReportExceptionDescription(env);
             message = (char *)JLI_MemAlloc((strlen(format) +
-					   strlen(classname)) * sizeof(char));
+                          strlen(classname)) * sizeof(char));
             messageDest = JNI_TRUE;
-	    sprintf(message, format, classname);
+            sprintf(message, format, classname);
             goto leave;
         }
         (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
@@ -1105,7 +1106,7 @@
             (void)strcat(env_entry, info.main_class);
         } else {
             ReportErrorMessage("Error: main-class: attribute exceeds system limits\n", JNI_TRUE);
-	    exit(1);
+            exit(1);
         }
     }
     (void)putenv(env_entry);
--- a/src/share/bin/java.h	Tue Mar 01 18:14:15 2011 -0800
+++ b/src/share/bin/java.h	Mon Mar 07 08:22:35 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -106,6 +106,7 @@
 jint ReadKnownVMs(const char *jrepath, char * arch, jboolean speculative);
 char *CheckJvmType(int *argc, char ***argv, jboolean speculative);
 void AddOption(char *str, void *info);
+void InitLauncher();
 
 /*
  * Make launcher spit debug output.
--- a/src/solaris/bin/java_md.c	Tue Mar 01 18:14:15 2011 -0800
+++ b/src/solaris/bin/java_md.c	Mon Mar 07 08:22:35 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -166,6 +166,11 @@
 }
 
 void
+InitLauncher() {
+   /* do nothing on Unix, add any future initialization here */
+}
+
+void
 CreateExecutionEnvironment(int *_argcp,
                            char ***_argvp,
                            char jrepath[],
--- a/src/windows/bin/java_md.c	Tue Mar 01 18:14:15 2011 -0800
+++ b/src/windows/bin/java_md.c	Mon Mar 07 08:22:35 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -60,6 +60,19 @@
 #endif
 }
 
+typedef BOOL (WINAPI *pfn_SetDllDirectory)(LPCTSTR);
+
+void
+InitLauncher() {
+    // Launcher links with kernel32
+    HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32.dll"));
+    pfn_SetDllDirectory fn = (pfn_SetDllDirectory) GetProcAddress(hKernel32,
+                                "SetDllDirectory");
+    if (fn != NULL) {
+        // Exclude CWD from Dll search path
+        fn("");
+    }
+}
 
 /*
  *