summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-09-27 15:39:40 -0400
committerNick Mathewson <nickm@torproject.org>2010-09-27 15:39:40 -0400
commite3859615429ec8d3939e21cd65fa07cc56bb5d0c (patch)
tree99112f8fa5bbf901f93551775c141178761d4b44
parent24a45f54d270d86dde456cbb45640811d1ba26c2 (diff)
parentd073d7d4ebd461a1550595d0180f0367b67bcc16 (diff)
downloadtor-e3859615429ec8d3939e21cd65fa07cc56bb5d0c.tar.gz
tor-e3859615429ec8d3939e21cd65fa07cc56bb5d0c.zip
Merge remote branch 'public/bug1954' into maint-0.2.2
-rw-r--r--changes/bug1954_loadlib4
-rw-r--r--src/common/util.c15
-rw-r--r--src/common/util.h4
-rw-r--r--src/or/eventdns.c3
-rw-r--r--src/or/ntmain.c3
-rw-r--r--src/test/test_util.c16
6 files changed, 41 insertions, 4 deletions
diff --git a/changes/bug1954_loadlib b/changes/bug1954_loadlib
new file mode 100644
index 0000000000..901d9baa5c
--- /dev/null
+++ b/changes/bug1954_loadlib
@@ -0,0 +1,4 @@
+ o Major bugfixes
+ - Always search the windows system directory for system DLLs, and
+ nowhere else. Fixes bug 1954.
+
diff --git a/src/common/util.c b/src/common/util.c
index abb2753c6e..b4f3052e19 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -26,6 +26,7 @@
#include <io.h>
#include <direct.h>
#include <process.h>
+#include <tchar.h>
#else
#include <dirent.h>
#include <pwd.h>
@@ -2862,3 +2863,17 @@ write_pidfile(char *filename)
}
}
+#ifdef MS_WINDOWS
+HANDLE
+load_windows_system_library(const TCHAR *library_name)
+{
+ TCHAR path[MAX_PATH];
+ unsigned n;
+ n = GetSystemDirectory(path, MAX_PATH);
+ if (n == 0 || n + _tcslen(library_name) + 2 >= MAX_PATH)
+ return 0;
+ _tcscat(path, TEXT("\\"));
+ _tcscat(path, library_name);
+ return LoadLibrary(path);
+}
+#endif
diff --git a/src/common/util.h b/src/common/util.h
index 4a31c277e3..833fd904c7 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -340,6 +340,10 @@ void start_daemon(void);
void finish_daemon(const char *desired_cwd);
void write_pidfile(char *filename);
+#ifdef MS_WINDOWS
+HANDLE load_windows_system_library(const TCHAR *library_name);
+#endif
+
const char *libor_get_digests(void);
#endif
diff --git a/src/or/eventdns.c b/src/or/eventdns.c
index 8ebfb79353..b929303fd5 100644
--- a/src/or/eventdns.c
+++ b/src/or/eventdns.c
@@ -3131,8 +3131,7 @@ load_nameservers_with_getnetworkparams(void)
IP_ADDR_STRING *ns;
GetNetworkParams_fn_t fn;
- /* XXXX Possibly, we should hardcode the location of this DLL. */
- if (!(handle = LoadLibrary(TEXT("iphlpapi.dll")))) {
+ if (!(handle = load_windows_system_library(TEXT("iphlpapi.dll")))) {
log(EVDNS_LOG_WARN, "Could not open iphlpapi.dll");
/* right now status = 0, doesn't that mean "good" - mikec */
status = -1;
diff --git a/src/or/ntmain.c b/src/or/ntmain.c
index 0b611f0bf1..46e7afb78b 100644
--- a/src/or/ntmain.c
+++ b/src/or/ntmain.c
@@ -138,8 +138,7 @@ nt_service_loadlibrary(void)
if (service_fns.loaded)
return;
- /* XXXX Possibly, we should hardcode the location of this DLL. */
- if (!(library = LoadLibrary(TEXT("advapi32.dll")))) {
+ if (!(library = load_windows_system_library(TEXT("advapi32.dll")))) {
log_err(LD_GENERAL, "Couldn't open advapi32.dll. Are you trying to use "
"NT services on Windows 98? That doesn't work.");
goto err;
diff --git a/src/test/test_util.c b/src/test/test_util.c
index d90927b35f..a14d548b8e 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1195,6 +1195,19 @@ test_util_listdir(void *ptr)
}
}
+#ifdef MS_WINDOWS
+static void
+test_util_load_win_lib(void *ptr)
+{
+ HANDLE h = load_windows_system_library("advapi32.dll");
+
+ tt_assert(h);
+ done:
+ if (h)
+ CloseHandle(h);
+}
+#endif
+
#define UTIL_LEGACY(name) \
{ #name, legacy_test_helper, 0, &legacy_setup, test_util_ ## name }
@@ -1218,6 +1231,9 @@ struct testcase_t util_tests[] = {
UTIL_TEST(find_str_at_start_of_line, 0),
UTIL_TEST(asprintf, 0),
UTIL_TEST(listdir, 0),
+#ifdef MS_WINDOWS
+ UTIL_TEST(load_win_lib, 0),
+#endif
END_OF_TESTCASES
};