summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-06-11 10:14:01 -0400
committerNick Mathewson <nickm@torproject.org>2012-06-11 10:14:01 -0400
commita6180b7f290c52b03f8abe3caf2ce233399dd66f (patch)
tree03e84ecf4e9f0b7cc401b3033f34197198cd8c84
parentcb01aaea12b5ed217a1af2595aa9d658c4a52709 (diff)
parentbf9252587b4d7d970f02631b308451fb05ec5560 (diff)
downloadtor-a6180b7f290c52b03f8abe3caf2ce233399dd66f.tar.gz
tor-a6180b7f290c52b03f8abe3caf2ce233399dd66f.zip
Merge branch 'bug6097'
-rw-r--r--changes/bug59095
-rw-r--r--changes/fix_unicode3
-rw-r--r--src/common/compat.c23
-rw-r--r--src/common/util.c7
-rw-r--r--src/or/config.c5
-rw-r--r--src/or/eventdns.c3
-rw-r--r--src/or/ntmain.c3
-rw-r--r--src/test/test.c2
-rw-r--r--src/test/test_util.c6
9 files changed, 41 insertions, 16 deletions
diff --git a/changes/bug5909 b/changes/bug5909
new file mode 100644
index 0000000000..61990faefa
--- /dev/null
+++ b/changes/bug5909
@@ -0,0 +1,5 @@
+ o Major bugfixes:
+ - When building Tor on Windows with -DUNICODE (not default),
+ ensure that error messages, filenames, and DNS server names are
+ always NUL-terminated when we convert them to a single-byte
+ encoding. Fixes bug 5909; bugfix on 0.2.2.16-alpha.
diff --git a/changes/fix_unicode b/changes/fix_unicode
new file mode 100644
index 0000000000..b97c393954
--- /dev/null
+++ b/changes/fix_unicode
@@ -0,0 +1,3 @@
+ o Minor bugfixes:
+ - Make Tor build correctly again with -DUNICODE -D_UNICODE defined.
+ Bugfix on 0.2.2.16-alpha; fixes bug 6097.
diff --git a/src/common/compat.c b/src/common/compat.c
index 91fa182c9a..71e39b6127 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -3046,28 +3046,37 @@ format_win32_error(DWORD err)
{
TCHAR *str = NULL;
char *result;
+ DWORD n;
/* Somebody once decided that this interface was better than strerror(). */
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPVOID)&str,
+ (LPVOID)&str,
0, NULL);
- if (str) {
+ if (str && n) {
#ifdef UNICODE
- char abuf[1024] = {0};
- wcstombs(abuf,str,1024);
- result = tor_strdup(abuf);
+ size_t len;
+ if (n > 128*1024)
+ len = (128 * 1024) * 2 + 1; /* This shouldn't be possible, but let's
+ * make sure. */
+ else
+ len = n * 2 + 1;
+ result = tor_malloc(len);
+ wcstombs(result,str,len);
+ result[len-1] = '\0';
#else
result = tor_strdup(str);
#endif
- LocalFree(str); /* LocalFree != free() */
} else {
result = tor_strdup("<unformattable error>");
}
+ if (str) {
+ LocalFree(str); /* LocalFree != free() */
+ }
return result;
}
#endif
diff --git a/src/common/util.c b/src/common/util.c
index 4c086e86fc..28ecff3983 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2855,7 +2855,7 @@ tor_listdir(const char *dirname)
#ifdef _WIN32
char *pattern=NULL;
TCHAR tpattern[MAX_PATH] = {0};
- char name[MAX_PATH] = {0};
+ char name[MAX_PATH*2+1] = {0};
HANDLE handle;
WIN32_FIND_DATA findData;
tor_asprintf(&pattern, "%s\\*", dirname);
@@ -2872,6 +2872,7 @@ tor_listdir(const char *dirname)
while (1) {
#ifdef UNICODE
wcstombs(name,findData.cFileName,MAX_PATH);
+ name[sizeof(name)-1] = '\0';
#else
strlcpy(name,findData.cFileName,sizeof(name));
#endif
@@ -3380,7 +3381,7 @@ tor_spawn_background(const char *const filename, const char **argv,
process_handle_t *process_handle;
int status;
- STARTUPINFO siStartInfo;
+ STARTUPINFOA siStartInfo;
BOOL retval = FALSE;
SECURITY_ATTRIBUTES saAttr;
@@ -3441,7 +3442,7 @@ tor_spawn_background(const char *const filename, const char **argv,
/* Create the child process */
- retval = CreateProcess(filename, // module name
+ retval = CreateProcessA(filename, // module name
joined_argv, // command line
/* TODO: should we set explicit security attributes? (#2046, comment 5) */
NULL, // process security attributes
diff --git a/src/or/config.c b/src/or/config.c
index 090d96c155..2e3ce6429d 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -4302,7 +4302,7 @@ static char *
get_windows_conf_root(void)
{
static int is_set = 0;
- static char path[MAX_PATH+1];
+ static char path[MAX_PATH*2+1];
TCHAR tpath[MAX_PATH] = {0};
LPITEMIDLIST idl;
@@ -4332,7 +4332,8 @@ get_windows_conf_root(void)
/* Convert the path from an "ID List" (whatever that is!) to a path. */
result = SHGetPathFromIDList(idl, tpath);
#ifdef UNICODE
- wcstombs(path,tpath,MAX_PATH);
+ wcstombs(path,tpath,sizeof(path));
+ path[sizeof(path)-1] = '\0';
#else
strlcpy(path,tpath,sizeof(path));
#endif
diff --git a/src/or/eventdns.c b/src/or/eventdns.c
index 61a28361ab..768693aba6 100644
--- a/src/or/eventdns.c
+++ b/src/or/eventdns.c
@@ -3213,7 +3213,7 @@ static int
config_nameserver_from_reg_key(HKEY key, const TCHAR *subkey)
{
char *buf;
- char ansibuf[MAX_PATH] = {0};
+ char ansibuf[MAX_PATH] = {0};
DWORD bufsz = 0, type = 0;
int status = 0;
@@ -3226,6 +3226,7 @@ config_nameserver_from_reg_key(HKEY key, const TCHAR *subkey)
if (RegQueryValueEx(key, subkey, 0, &type, (LPBYTE)buf, &bufsz)
== ERROR_SUCCESS && bufsz > 1) {
wcstombs(ansibuf,(wchar_t*)buf,MAX_PATH);/*XXXX UNICODE */
+ abuf[MAX_PATH-1] = '\0';
status = evdns_nameserver_ip_add_line(ansibuf);
}
diff --git a/src/or/ntmain.c b/src/or/ntmain.c
index 01244c4c08..d001f7be13 100644
--- a/src/or/ntmain.c
+++ b/src/or/ntmain.c
@@ -455,7 +455,7 @@ static char *
nt_service_command_line(int *using_default_torrc)
{
TCHAR tor_exe[MAX_PATH+1];
- char tor_exe_ascii[MAX_PATH+1];
+ char tor_exe_ascii[MAX_PATH*2+1];
char *command=NULL, *options=NULL;
smartlist_t *sl;
int i;
@@ -483,6 +483,7 @@ nt_service_command_line(int *using_default_torrc)
#ifdef UNICODE
wcstombs(tor_exe_ascii, tor_exe, sizeof(tor_exe_ascii));
+ tor_exe_ascii[sizeof(tor_exe_ascii)-1] = '\0';
#else
strlcpy(tor_exe_ascii, tor_exe, sizeof(tor_exe_ascii));
#endif
diff --git a/src/test/test.c b/src/test/test.c
index 4f19f36eab..89b4ced87c 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -91,7 +91,7 @@ setup_directory(void)
char buf[MAX_PATH];
const char *tmp = buf;
/* If this fails, we're probably screwed anyway */
- if (!GetTempPath(sizeof(buf),buf))
+ if (!GetTempPathA(sizeof(buf),buf))
tmp = "c:\\windows\\temp";
tor_snprintf(temp_dir, sizeof(temp_dir),
"%s\\tor_test_%d", tmp, (int)getpid());
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 4b628ea54d..7484b9e90f 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -14,6 +14,10 @@
#include "mempool.h"
#include "memarea.h"
+#ifdef _WIN32
+#include <tchar.h>
+#endif
+
static void
test_util_time(void)
{
@@ -2113,7 +2117,7 @@ test_util_parent_dir(void *ptr)
static void
test_util_load_win_lib(void *ptr)
{
- HANDLE h = load_windows_system_library("advapi32.dll");
+ HANDLE h = load_windows_system_library(_T("advapi32.dll"));
(void) ptr;
tt_assert(h);