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

Skip to content

Commit 8a79dcc

Browse files
author
Victor Stinner
committed
_Py_stat(): ensure that path ends with a nul character
1 parent 09245d8 commit 8a79dcc

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Python/import.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,10 +1976,11 @@ _Py_stat(PyObject *unicode, struct stat *statbuf)
19761976
int err;
19771977
struct _stat wstatbuf;
19781978

1979-
len = PyUnicode_AsWideChar((PyUnicodeObject*)unicode, path,
1980-
sizeof(path) / sizeof(path[0]));
1979+
len = PyUnicode_AsWideChar((PyUnicodeObject*)unicode, path, MAXPATHLEN);
19811980
if (len == -1)
19821981
return -1;
1982+
path[len] = L'\0';
1983+
19831984
err = _wstat(path, &wstatbuf);
19841985
if (!err)
19851986
statbuf->st_mode = wstatbuf.st_mode;

0 commit comments

Comments
 (0)