]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-102281: Fix potential nullptr dereference + use of uninitia… (#103040)
authorMax Bachmann <kontakt@maxbachmann.de>
Sat, 25 Mar 2023 23:35:00 +0000 (00:35 +0100)
committerGitHub <noreply@github.com>
Sat, 25 Mar 2023 23:35:00 +0000 (16:35 -0700)
[3.11] gh-102281: Fix potential nullptr dereference + use of uninitialized memory (gh-102282)
(cherry picked from commit afa6092ee4260bacf7bc11905466e4c3f8556cbb)

Misc/NEWS.d/next/Core and Builtins/2023-03-02-13-49-21.gh-issue-102281.QCuu2N.rst [new file with mode: 0644]
Modules/getpath.c
Python/fileutils.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-03-02-13-49-21.gh-issue-102281.QCuu2N.rst b/Misc/NEWS.d/next/Core and Builtins/2023-03-02-13-49-21.gh-issue-102281.QCuu2N.rst
new file mode 100644 (file)
index 0000000..b0269dd
--- /dev/null
@@ -0,0 +1 @@
+Fix potential nullptr dereference and use of uninitialized memory in fileutils. Patch by Max Bachmann.
index ceacf36d8968a1fe268b6b66ff4373abde4dfb5f..bc730fcd7dc7573e95163d4f013c594d2aa1111e 100644 (file)
@@ -452,7 +452,10 @@ getpath_realpath(PyObject *Py_UNUSED(self) , PyObject *args)
             if (s) {
                 *s = L'\0';
             }
-            path2 = _Py_normpath(_Py_join_relfile(path, resolved), -1);
+            path2 = _Py_join_relfile(path, resolved);
+            if (path2) {
+                path2 = _Py_normpath(path2, -1);
+            }
             PyMem_RawFree((void *)path);
             path = path2;
         }
index 27924261f439619a572969ab56efea13bbb75504..c86ed40b19937e5b7d003cd6ed884863280bb1de 100644 (file)
@@ -2142,7 +2142,10 @@ _Py_join_relfile(const wchar_t *dirname, const wchar_t *relfile)
     }
     assert(wcslen(dirname) < MAXPATHLEN);
     assert(wcslen(relfile) < MAXPATHLEN - wcslen(dirname));
-    join_relfile(filename, bufsize, dirname, relfile);
+    if (join_relfile(filename, bufsize, dirname, relfile) < 0) {
+        PyMem_RawFree(filename);
+        return NULL;
+    }
     return filename;
 }
 
@@ -2180,6 +2183,7 @@ _Py_find_basename(const wchar_t *filename)
 wchar_t *
 _Py_normpath(wchar_t *path, Py_ssize_t size)
 {
+    assert(path != NULL);
     if (!path[0] || size == 0) {
         return path;
     }