gh-130163: Fix usage of borrow references from _PySys_GetAttr #130282
+315
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP
print
and concurrently modifyingsys.stdout
#130163_pickle.c/whichmodule
_threadmodule.c/thread_excepthook
faulthandler.c/faulthandler_get_fileno
bltinmodule.c/builtin_print_impl
bltinmodule.c/builtin_input_impl
errors.c/write_unraisable_exc
errors.c/format_unraisable_v
_warnings.c/show_warning
intrinsics.c/print_expr
pylifecycle.c/flush_std_files
pythonrun.c/_PyRun_InteractiveLoopObject
pythonrun.c/pyrun_one_parse_ast
pythonrun.c/_Py_HandleSystemExitAndKeyboardInterrupt
pythonrun.c/_PyErr_PrintEx
pythonrun.c/PyErr_Display
pythonrun.c/flush_io_stream
sysmodule.c/sys_displayhook
sysmodule.c/get_warnoptions
sysmodule.c/PySys_ResetWarnOptions
sysmodule.c/PySys_HasWarnOptions
sysmodule.c/_PySys_AddXOptionWithError
sysmodule.c/PySys_SetArgvEx
sysmodule.c/sys_write
sysmodule.c/sys_format
traceback.c/_Py_FindSourceFile
sys_displayhook
, but not where it's used.sys_write
,sys_format
- I have checked all the places where they called, and most of the locations are safe. However, a few places use%s
specifier, in such places it is very tricky to getsegfault
.get_warnoptions
,PySys_ResetWarnOptions
,_PySys_AddXOptionWithError
- are deprecated, but it is a very tricky to getsegfault
too.flush_io_stream
,PyErr_Display
,pyrun_one_parse_ast
,print_expr
,write_unraisable_exc
,thread_excepthook
- very tight - They use a borrowed reference right after getting. It might be possible to reproduce it under heavy contention, but I wasn't able to do so._PyRun_InteractiveLoopObject
only checks presence ofps1
andps2
.flush_std_files
used from_Py_Finalize
and fromfatal_error
. For_Py_Finalize
I can repro, forfatal_error
- no.whichmodule
,_Py_FindSourceFile
iterate borrowed reference, but I wasn't able to reproducesegfault
._PySys_GetAttr
called without an exception set.