Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SystemError from termios.tcsetwinsizepassing NULL to PyLong_AsLong #146091

Copy link
Copy link
@devdanzin

Description

@devdanzin
Issue body actions

Crash report

What happened?

It's possible to raise SystemError from termios.tcsetwinsize by passing a sequence that raises on __getitem__ to it.

Automated diagnosis:

Bug: termios.tcsetwinsize passes NULL to PyLong_AsLong. PySequence_GetItem(winsz, 0) can return NULL (e.g., __getitem__ raises). The result is passed directly to PyLong_AsLong(NULL) which calls PyErr_BadInternalCall(), masking the real error with SystemError.

File: Modules/termios.c, lines 502-510

MRE:

import termios
import os

fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)

class BadSequence:
    def __len__(self):
        return 2
    def __getitem__(self, idx):
        raise TypeError

termios.tcsetwinsize(fd, BadSequence())

Backtrace:

Traceback (most recent call last):
  File "/home/danzin/crashers/trigger_termios_null_pylong.py", line 23, in <module>
    termios.tcsetwinsize(fd, BadSequence())
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
SystemError: Objects/longobject.c:598: bad argument to internal function

Found using cpython-review-toolkit with Claude Opus 4.6, using the /cpython-review-toolkit:explore Modules/termios.c all deep command.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.15.0a7+ (heads/main:e0f7c1097e1, Mar 17 2026, 18:10:52) [Clang 21.1.2 (2ubuntu6)]

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.