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

Skip to content

gh-98978: Fix use-after-free in apps that call pathconfig global functions multiple times #99007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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 @@
Fixed a potential use-after-free in applications that call configuration
functions :c:func:`Py_SetPythonHome`, :c:func:`Py_SetProgramName` or
(private) ``_Py_SetProgramFullPath`` multiple times.
12 changes: 3 additions & 9 deletions Python/pathconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ Py_SetPythonHome(const wchar_t *home)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

PyMem_RawFree(_Py_path_config.home);
if (has_value) {
_Py_path_config.home = _PyMem_RawWcsdup(home);
}
_Py_path_config.home = has_value ? _PyMem_RawWcsdup(home) : NULL;

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

Expand All @@ -282,9 +280,7 @@ Py_SetProgramName(const wchar_t *program_name)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

PyMem_RawFree(_Py_path_config.program_name);
if (has_value) {
_Py_path_config.program_name = _PyMem_RawWcsdup(program_name);
}
_Py_path_config.program_name = has_value ? _PyMem_RawWcsdup(program_name) : NULL;

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

Expand All @@ -302,9 +298,7 @@ _Py_SetProgramFullPath(const wchar_t *program_full_path)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

PyMem_RawFree(_Py_path_config.program_full_path);
if (has_value) {
_Py_path_config.program_full_path = _PyMem_RawWcsdup(program_full_path);
}
_Py_path_config.program_full_path = has_value ? _PyMem_RawWcsdup(program_full_path) : NULL;

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

Expand Down