Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2010-12-20 20:46:47 +0000
committerAndrew Niefer2010-12-20 20:46:47 +0000
commit7e51460f541423319a6bb00b790e9f97801ec54d (patch)
treeaa2032d7708a63349edf0f4915a07cbcaaad408e
parentd9751f0ca5947ac5f0f30d2a6299ef5fb8845ddd (diff)
downloadrt.equinox.framework-7e51460f541423319a6bb00b790e9f97801ec54d.tar.gz
rt.equinox.framework-7e51460f541423319a6bb00b790e9f97801ec54d.tar.xz
rt.equinox.framework-7e51460f541423319a6bb00b790e9f97801ec54d.zip
Bug 325902 - loadLibrary & cwd
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipse.c21
-rw-r--r--bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c16
2 files changed, 34 insertions, 3 deletions
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipse.c b/bundles/org.eclipse.equinox.executable/library/eclipse.c
index 65c0c26ef..410e62c7f 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipse.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipse.c
@@ -355,6 +355,7 @@ static const _TCHAR* getVMArch();
#ifdef _WIN32
static void createConsole();
+static void fixDLLSearchPath();
static int isConsoleLauncher();
#endif
static int consoleLauncher = 0;
@@ -415,6 +416,9 @@ JNIEXPORT int run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[])
#elif _WIN32
/* this must be before doing any console stuff, platforms other than win32 leave this set to 0 */
consoleLauncher = isConsoleLauncher();
+
+ /*fix the DLL search path for security */
+ fixDLLSearchPath();
#endif
/* Find the directory where the Eclipse program is installed. */
@@ -1373,6 +1377,23 @@ static int isConsoleLauncher() {
}
return 0;
}
+
+static void fixDLLSearchPath() {
+#ifdef UNICODE
+ _TCHAR* functionName = _T_ECLIPSE("SetDllDirectoryW");
+#else
+ _TCHAR* functionName = _T_ECLIPSE("SetDllDirectoryA");
+#endif
+
+ BOOL (WINAPI *SetDLLDirectory)(LPCTSTR);
+ void * handle = loadLibrary(_T_ECLIPSE("Kernel32.dll"));
+ if (handle != NULL) {
+ if ( (SetDLLDirectory = findSymbol(handle, functionName)) != NULL) {
+ SetDLLDirectory(_T_ECLIPSE(""));
+ }
+ }
+}
+
#endif
/* Set the vm to use based on the given .ee file.
diff --git a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
index 8033224ae..770b464a6 100644
--- a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
+++ b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
@@ -286,6 +286,7 @@ _TCHAR * findVMLibrary( _TCHAR* command ) {
void adjustSearchPath( _TCHAR* vmLib ){
_TCHAR ** paths;
+ _TCHAR* cwd = NULL;
_TCHAR * path = NULL, *newPath = NULL;
_TCHAR * c;
int i, length;
@@ -293,12 +294,20 @@ void adjustSearchPath( _TCHAR* vmLib ){
paths = getVMLibrarySearchPath(vmLib);
+ /* bug 325902 - add current working dir to the end of the search path */
+ length = GetCurrentDirectory(0, NULL);
+ cwd = malloc((length + 1)* sizeof(_TCHAR));
+ GetCurrentDirectory(length, cwd);
+ cwd[length - 1] = pathSeparator;
+ cwd[length] = 0;
+
/* first call to GetEnvironmentVariable tells us how big to make the buffer */
length = GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, 0);
if (length > 0) {
+ _TCHAR* current [] = { cwd, NULL };
path = malloc(length * sizeof(_TCHAR));
GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, length);
- needAdjust = !containsPaths(path, paths);
+ needAdjust = !containsPaths(path, paths) || !containsPaths(path, current);
freePath = 1;
} else {
path = _T_ECLIPSE("");
@@ -308,8 +317,8 @@ void adjustSearchPath( _TCHAR* vmLib ){
if (needAdjust) {
c = concatStrings(paths);
- newPath = malloc((_tcslen(c) + length + 1) * sizeof(_TCHAR));
- _stprintf(newPath, _T_ECLIPSE("%s%s"), c, path);
+ newPath = malloc((_tcslen(c) + length + 1 + _tcslen(cwd) + 1) * sizeof(_TCHAR));
+ _stprintf(newPath, _T_ECLIPSE("%s%s%c%s"), c, path, pathSeparator, cwd);
SetEnvironmentVariable( _T_ECLIPSE("PATH"), newPath);
free(c);
free(newPath);
@@ -318,6 +327,7 @@ void adjustSearchPath( _TCHAR* vmLib ){
for (i = 0; paths[i] != NULL; i++)
free(paths[i]);
free(paths);
+ free(cwd);
if (freePath)
free(path);
}

Back to the top