diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-16 22:55:47 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-16 22:55:47 (GMT) |
commit | 0a1b8cba90d467e85be87cd8b10b4d31caa8765a (patch) | |
tree | 7162df88fee483d68c69ef5a29c5f3b6f8438b96 | |
parent | 350147b5cacee7a288875007cddf1f7a321a21e2 (diff) | |
download | cpython-0a1b8cba90d467e85be87cd8b10b4d31caa8765a.zip cpython-0a1b8cba90d467e85be87cd8b10b4d31caa8765a.tar.gz cpython-0a1b8cba90d467e85be87cd8b10b4d31caa8765a.tar.bz2 |
_Py_wrealpath() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
-rw-r--r-- | Python/fileutils.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index 147636f..b8910b7 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -353,6 +353,7 @@ _Py_wrealpath(const wchar_t *path, { char *cpath; char cresolved_path[PATH_MAX]; + wchar_t *wresolved_path; char *res; size_t r; cpath = _Py_wchar2char(path); @@ -364,11 +365,20 @@ _Py_wrealpath(const wchar_t *path, PyMem_Free(cpath); if (res == NULL) return NULL; - r = mbstowcs(resolved_path, cresolved_path, resolved_path_size); - if (r == (size_t)-1 || r >= PATH_MAX) { + + wresolved_path = _Py_char2wchar(cresolved_path); + if (wresolved_path == NULL) { + errno = EINVAL; + return NULL; + } + r = wcslen(wresolved_path); + if (resolved_path_size <= r) { + PyMem_Free(wresolved_path); errno = EINVAL; return NULL; } + wcsncpy(resolved_path, wresolved_path, resolved_path_size); + PyMem_Free(wresolved_path); return resolved_path; } #endif |