1. Armin Rigo
  2. cpython-withatomic

Commits

Victor Stinner  committed 8fd5d06

_Py_wrealpath() requires the size of the output buffer

  • Participants
  • Parent commits 2147cc1
  • Branches default

Comments (0)

Files changed (3)

File Include/fileutils.h

View file
  • Ignore whitespace
 #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(

File Python/fileutils.c

View file
  • Ignore whitespace
 
 #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;

File Python/sysmodule.c

View file
  • Ignore whitespace
 #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