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

Segmentation fault when overriding sys.stderr #87826

Closed
pablogsal opened this issue Mar 29, 2021 · 6 comments
Closed

Segmentation fault when overriding sys.stderr #87826

pablogsal opened this issue Mar 29, 2021 · 6 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@pablogsal
Copy link
Member

BPO 43660
Nosy @vstinner, @pablogsal, @miss-islington
PRs
  • bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr #25075
  • [3.9] bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075) #25083
  • [3.8] bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075) #25084
  • [3.7] bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075). #25085
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-03-29.23:50:17.702>
    created_at = <Date 2021-03-29.18:42:46.525>
    labels = ['interpreter-core', '3.7', '3.8', '3.9', '3.10']
    title = 'Segmentation fault when overriding sys.stderr'
    updated_at = <Date 2021-03-29.23:50:17.702>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2021-03-29.23:50:17.702>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-29.23:50:17.702>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2021-03-29.18:42:46.525>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43660
    keywords = ['patch']
    message_count = 6.0
    messages = ['389722', '389723', '389764', '389769', '389771', '389772']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'pablogsal', 'miss-islington']
    pr_nums = ['25075', '25083', '25084', '25085']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43660'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @pablogsal
    Copy link
    Member Author

    This code crashes (reported by the one and only Matt Wozniski):

    import sys
    class MyStderr:
        def write(self, s):
            sys.stderr = None
    sys.stderr = MyStderr()
    1/0

    [1] 34112 segmentation fault ./python.exe lel.py

    @pablogsal pablogsal added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Mar 29, 2021
    @pablogsal
    Copy link
    Member Author

    The problem is that https://github.com/python/cpython/blob/master/Python/pythonrun.c#L1074 doesn't take a strong reference to sys.stderr but code underneath can potentially release the GIL and remove the reference that keeps the object alive.

    @pablogsal
    Copy link
    Member Author

    New changeset 09b90a0 by Pablo Galindo in branch 'master':
    bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075)
    09b90a0

    @miss-islington
    Copy link
    Contributor

    New changeset ba7f863 by Miss Islington (bot) in branch '3.8':
    bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075)
    ba7f863

    @pablogsal
    Copy link
    Member Author

    New changeset 2f01c56 by Pablo Galindo in branch '3.7':
    [3.7] bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075). (GH-25085)
    2f01c56

    @pablogsal
    Copy link
    Member Author

    New changeset ff4715a by Miss Islington (bot) in branch '3.9':
    bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075) (GH-25083)
    ff4715a

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants