Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix use-after-free in ``Py_SetPythonHome(NULL)``,
``Py_SetProgramName(NULL)`` and ``_Py_SetProgramFullPath(NULL)`` function
calls. Issue reported by Benedikt Reinartz. Patch by Victor Stinner.
6 changes: 6 additions & 0 deletions Python/pathconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ Py_SetPythonHome(const wchar_t *home)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

PyMem_RawFree(_Py_path_config.home);
_Py_path_config.home = NULL;

if (has_value) {
_Py_path_config.home = _PyMem_RawWcsdup(home);
}
Expand All @@ -282,6 +284,8 @@ Py_SetProgramName(const wchar_t *program_name)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

PyMem_RawFree(_Py_path_config.program_name);
_Py_path_config.program_name = NULL;

if (has_value) {
_Py_path_config.program_name = _PyMem_RawWcsdup(program_name);
}
Expand All @@ -302,6 +306,8 @@ _Py_SetProgramFullPath(const wchar_t *program_full_path)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

PyMem_RawFree(_Py_path_config.program_full_path);
_Py_path_config.program_full_path = NULL;

if (has_value) {
_Py_path_config.program_full_path = _PyMem_RawWcsdup(program_full_path);
}
Expand Down