Victor Stinner avatar Victor Stinner committed 8fd5d06

_Py_wrealpath() requires the size of the output buffer

Comments (0)

Files changed (3)

Include/fileutils.h

 #ifdef HAVE_REALPATH
 PyAPI_FUNC(wchar_t*) _Py_wrealpath(
     const wchar_t *path,
-    wchar_t *resolved_path);
+    wchar_t *resolved_path,
+    size_t resolved_path_size);
 #endif
 
 PyAPI_FUNC(wchar_t*) _Py_wgetcwd(

Python/fileutils.c

 
 #ifdef HAVE_REALPATH
 wchar_t*
-_Py_wrealpath(const wchar_t *path, wchar_t *resolved_path)
+_Py_wrealpath(const wchar_t *path,
+              wchar_t *resolved_path, size_t resolved_path_size)
 {
     char *cpath;
     char cresolved_path[PATH_MAX];
     PyMem_Free(cpath);
     if (res == NULL)
         return NULL;
-    r = mbstowcs(resolved_path, cresolved_path, PATH_MAX);
+    r = mbstowcs(resolved_path, cresolved_path, resolved_path_size);
     if (r == (size_t)-1 || r >= PATH_MAX) {
         errno = EINVAL;
         return NULL;

Python/sysmodule.c

 #else /* All other filename syntaxes */
     if (_HAVE_SCRIPT_ARGUMENT(argc, argv)) {
 #if defined(HAVE_REALPATH)
-        if (_Py_wrealpath(argv0, fullpath)) {
+        if (_Py_wrealpath(argv0, fullpath, PATH_MAX)) {
             argv0 = fullpath;
         }
 #endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.