summaryrefslogtreecommitdiff
path: root/Python/fileutils.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 22:55:47 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 22:55:47 +0000
commit4e7ceabd43ad27956ac0014ce5ff16995fd5c03d (patch)
tree28cbddddb0f3d97879d8228f433ad933eb2bae2d /Python/fileutils.c
parent560612a9ad4dc53b764e2e0cc1137c7687f1d2c3 (diff)
downloadcpython-4e7ceabd43ad27956ac0014ce5ff16995fd5c03d.tar.gz
_Py_wrealpath() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 147636f2c7..b8910b7be6 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