diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-06-11 10:14:01 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-06-11 10:14:01 -0400 |
commit | a6180b7f290c52b03f8abe3caf2ce233399dd66f (patch) | |
tree | 03e84ecf4e9f0b7cc401b3033f34197198cd8c84 /src/common | |
parent | cb01aaea12b5ed217a1af2595aa9d658c4a52709 (diff) | |
parent | bf9252587b4d7d970f02631b308451fb05ec5560 (diff) | |
download | tor-a6180b7f290c52b03f8abe3caf2ce233399dd66f.tar.gz tor-a6180b7f290c52b03f8abe3caf2ce233399dd66f.zip |
Merge branch 'bug6097'
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 23 | ||||
-rw-r--r-- | src/common/util.c | 7 |
2 files changed, 20 insertions, 10 deletions
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 |