]> granicus.if.org Git - python/commitdiff
_Py_wrealpath() requires the size of the output buffer
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 7 Oct 2010 22:29:53 +0000 (22:29 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 7 Oct 2010 22:29:53 +0000 (22:29 +0000)
Include/fileutils.h
Python/fileutils.c
Python/sysmodule.c

index 1d8df15d3c05b187bbe0aafa42da629626e638f0..a232460ef868b373592b778194732fcbcf352ced 100644 (file)
@@ -41,7 +41,8 @@ PyAPI_FUNC(int) _Py_wreadlink(
 #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(
index bd6ab5d3038f1fa878da5bdcadd084e89f4b2d24..502868f98c8d2eb3ccd8a4f201ee43278fef9eb5 100644 (file)
@@ -321,7 +321,8 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
 
 #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];
@@ -336,7 +337,7 @@ _Py_wrealpath(const wchar_t *path, wchar_t *resolved_path)
     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;
index 1eba28edd1d41206afad88b0340813645ab7ee7e..d02ee5b5c08032abc6f6a9bb5db07243b0c01cd2 100644 (file)
@@ -1742,7 +1742,7 @@ sys_update_path(int argc, wchar_t **argv)
 #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