diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-05-17 10:08:48 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-06-07 11:09:38 -0400 |
commit | 1e5683b167a612bf76d4ae9ba508027e0d473e52 (patch) | |
tree | 5bd336b4f17411122c8ddb152324f8c2922d4d6e /src/or/config.c | |
parent | 99618a9641d02b7b99a79c71517203bb70043515 (diff) | |
download | tor-1e5683b167a612bf76d4ae9ba508027e0d473e52.tar.gz tor-1e5683b167a612bf76d4ae9ba508027e0d473e52.zip |
Be more careful calling wcstombs
The function is not guaranteed to NUL-terminate its output. It
*is*, however, guaranteed not to generate more than two bytes per
multibyte character (plus terminating nul), so the general approach
I'm taking is to try to allocate enough space, AND to manually add a
NUL at the end of each buffer just in case I screwed up the "enough
space" thing.
Fixes bug 5909.
Diffstat (limited to 'src/or/config.c')
-rw-r--r-- | src/or/config.c | 5 |
1 files changed, 3 insertions, 2 deletions
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 |