Skip to content

Commit b07f546

Browse files
authored
pythongh-98978: Fix Py_SetPythonHome(NULL) (python#99066)
Fix use-after-free in Py_SetPythonHome(NULL), Py_SetProgramName(NULL) and _Py_SetProgramFullPath(NULL) function calls. Issue reported by Benedikt Reinartz.
1 parent ef0e72b commit b07f546

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix use-after-free in ``Py_SetPythonHome(NULL)``,
2+
``Py_SetProgramName(NULL)`` and ``_Py_SetProgramFullPath(NULL)`` function
3+
calls. Issue reported by Benedikt Reinartz. Patch by Victor Stinner.

Python/pathconfig.c

+6
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ Py_SetPythonHome(const wchar_t *home)
261261
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
262262

263263
PyMem_RawFree(_Py_path_config.home);
264+
_Py_path_config.home = NULL;
265+
264266
if (has_value) {
265267
_Py_path_config.home = _PyMem_RawWcsdup(home);
266268
}
@@ -282,6 +284,8 @@ Py_SetProgramName(const wchar_t *program_name)
282284
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
283285

284286
PyMem_RawFree(_Py_path_config.program_name);
287+
_Py_path_config.program_name = NULL;
288+
285289
if (has_value) {
286290
_Py_path_config.program_name = _PyMem_RawWcsdup(program_name);
287291
}
@@ -302,6 +306,8 @@ _Py_SetProgramFullPath(const wchar_t *program_full_path)
302306
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
303307

304308
PyMem_RawFree(_Py_path_config.program_full_path);
309+
_Py_path_config.program_full_path = NULL;
310+
305311
if (has_value) {
306312
_Py_path_config.program_full_path = _PyMem_RawWcsdup(program_full_path);
307313
}

0 commit comments

Comments
 (0)