7016985: (launcher) implement safe secure dll loading
authorksrini
Mon Mar 07 08:22:35 2011 -0800 (2 years ago)
changeset 50516fbb8d0b834
parent 50450636a6053f8
child 506bfc1a4516e20
7016985: (launcher) implement safe secure dll loading
Reviewed-by: asaha
src/share/bin/java.c
src/share/bin/java.h
src/solaris/bin/java_md.c
src/windows/bin/java_md.c
--- 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 @@ main(int argc, char ** argv)
}
}
-
+ /* this should be called before anything else */
+ InitLauncher();
/*
* Make sure the specified version of the JRE is running.
@@ -501,9 +502,9 @@ JavaMain(void * _args)
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 @@ SelectVersion(int argc, char **argv, cha
(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, c
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
@@ -163,6 +163,11 @@ GetArch()
GetArch()
{
return LIBARCHNAME;
+}
+
+void
+InitLauncher() {
+ /* do nothing on Unix, add any future initialization here */
}
void
--- 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 @@ GetArch()
#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("");
+ }
+}
/*
*