Skip to content

Commit 81328f3

Browse files
authored
bpo-41056: Fix reference to deallocated stack in pathconfig (Coverity) (GH-21013)
Reported by Coverity. (CID 1457554 RETURN_LOCAL) path0 is assigned as a pointer to this right before it goes out of scope.
1 parent 6f79838 commit 81328f3

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes a reference to deallocated stack space during startup when constructing sys.path involving a relative symlink when code was supplied via -c. (discovered via Coverity)

Python/pathconfig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ _PyPathConfig_ComputeSysPath0(const PyWideStringList *argv, PyObject **path0_p)
686686
#ifdef HAVE_READLINK
687687
wchar_t link[MAXPATHLEN + 1];
688688
int nr = 0;
689+
wchar_t path0copy[2 * MAXPATHLEN + 1];
689690

690691
if (have_script_arg) {
691692
nr = _Py_wreadlink(path0, link, Py_ARRAY_LENGTH(link));
@@ -708,7 +709,6 @@ _PyPathConfig_ComputeSysPath0(const PyWideStringList *argv, PyObject **path0_p)
708709
}
709710
else {
710711
/* Must make a copy, path0copy has room for 2 * MAXPATHLEN */
711-
wchar_t path0copy[2 * MAXPATHLEN + 1];
712712
wcsncpy(path0copy, path0, MAXPATHLEN);
713713
q = wcsrchr(path0copy, SEP);
714714
wcsncpy(q+1, link, MAXPATHLEN);

0 commit comments

Comments
 (0)