Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a1b8cb

Browse files
author
Victor Stinner
committed
_Py_wrealpath() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
1 parent 350147b commit 0a1b8cb

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Python/fileutils.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ _Py_wrealpath(const wchar_t *path,
353353
{
354354
char *cpath;
355355
char cresolved_path[PATH_MAX];
356+
wchar_t *wresolved_path;
356357
char *res;
357358
size_t r;
358359
cpath = _Py_wchar2char(path);
@@ -364,11 +365,20 @@ _Py_wrealpath(const wchar_t *path,
364365
PyMem_Free(cpath);
365366
if (res == NULL)
366367
return NULL;
367-
r = mbstowcs(resolved_path, cresolved_path, resolved_path_size);
368-
if (r == (size_t)-1 || r >= PATH_MAX) {
368+
369+
wresolved_path = _Py_char2wchar(cresolved_path);
370+
if (wresolved_path == NULL) {
371+
errno = EINVAL;
372+
return NULL;
373+
}
374+
r = wcslen(wresolved_path);
375+
if (resolved_path_size <= r) {
376+
PyMem_Free(wresolved_path);
369377
errno = EINVAL;
370378
return NULL;
371379
}
380+
wcsncpy(resolved_path, wresolved_path, resolved_path_size);
381+
PyMem_Free(wresolved_path);
372382
return resolved_path;
373383
}
374384
#endif

0 commit comments

Comments
 (0)