Skip to content

Commit b28f919

Browse files
authored
[3.11] gh-102281: Fix potential nullptr dereference + use of uninitia… (#103040)
[3.11] gh-102281: Fix potential nullptr dereference + use of uninitialized memory (gh-102282) (cherry picked from commit afa6092)
1 parent e1094c6 commit b28f919

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix potential nullptr dereference and use of uninitialized memory in fileutils. Patch by Max Bachmann.

Modules/getpath.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,10 @@ getpath_realpath(PyObject *Py_UNUSED(self) , PyObject *args)
452452
if (s) {
453453
*s = L'\0';
454454
}
455-
path2 = _Py_normpath(_Py_join_relfile(path, resolved), -1);
455+
path2 = _Py_join_relfile(path, resolved);
456+
if (path2) {
457+
path2 = _Py_normpath(path2, -1);
458+
}
456459
PyMem_RawFree((void *)path);
457460
path = path2;
458461
}

Python/fileutils.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,10 @@ _Py_join_relfile(const wchar_t *dirname, const wchar_t *relfile)
21422142
}
21432143
assert(wcslen(dirname) < MAXPATHLEN);
21442144
assert(wcslen(relfile) < MAXPATHLEN - wcslen(dirname));
2145-
join_relfile(filename, bufsize, dirname, relfile);
2145+
if (join_relfile(filename, bufsize, dirname, relfile) < 0) {
2146+
PyMem_RawFree(filename);
2147+
return NULL;
2148+
}
21462149
return filename;
21472150
}
21482151

@@ -2180,6 +2183,7 @@ _Py_find_basename(const wchar_t *filename)
21802183
wchar_t *
21812184
_Py_normpath(wchar_t *path, Py_ssize_t size)
21822185
{
2186+
assert(path != NULL);
21832187
if (!path[0] || size == 0) {
21842188
return path;
21852189
}

0 commit comments

Comments
 (0)