Skip to content
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

gh-130163: Fix usage of borrow references from _PySys_GetAttr #130282

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

sergey-miryanov
Copy link
Contributor

@sergey-miryanov sergey-miryanov commented Feb 18, 2025

WIP

Repro Tests Raised exception
_pickle.c/whichmodule No No Don't keep
_threadmodule.c/thread_excepthook No No Keep
faulthandler.c/faulthandler_get_fileno Yes Yes Don't keep
bltinmodule.c/builtin_print_impl Yes Yes Don't keep
bltinmodule.c/builtin_input_impl Yes Yes Don't keep
errors.c/write_unraisable_exc No No Keep
errors.c/format_unraisable_v Yes Yes Keep
_warnings.c/show_warning Yes Yes Don't keep
intrinsics.c/print_expr No No Don't keep
pylifecycle.c/flush_std_files Yes/No Yes/No Don't keep
pythonrun.c/_PyRun_InteractiveLoopObject No No Don't keep
pythonrun.c/pyrun_one_parse_ast No No Don't keep
pythonrun.c/_Py_HandleSystemExitAndKeyboardInterrupt No No Don't keep
pythonrun.c/_PyErr_PrintEx Yes Yes Don't keep
pythonrun.c/PyErr_Display No No Don't keep
pythonrun.c/flush_io_stream No No Don't keep
sysmodule.c/sys_displayhook Maybe No Don't keep
sysmodule.c/get_warnoptions No No Don't keep
sysmodule.c/PySys_ResetWarnOptions No No Don't keep
sysmodule.c/PySys_HasWarnOptions No No Don't keep
sysmodule.c/_PySys_AddXOptionWithError No No Don't keep
sysmodule.c/PySys_SetArgvEx No No Don't keep
sysmodule.c/sys_write No No Don't keep
sysmodule.c/sys_format No No Don't keep
traceback.c/_Py_FindSourceFile No No Don't keep
  • I can get a "segfault" error when I use sys_displayhook, but not where it's used.
  • For 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 get segfault.
  • get_warnoptions, PySys_ResetWarnOptions, _PySys_AddXOptionWithError - are deprecated, but it is a very tricky to get segfault 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 of ps1 and ps2.
  • flush_std_files used from _Py_Finalize and from fatal_error. For _Py_Finalize I can repro, for fatal_error - no.
  • whichmodule, _Py_FindSourceFile iterate borrowed reference, but I wasn't able to reproduce segfault.
  • Keep or not before raised exception - in the most places _PySys_GetAttr called without an exception set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant