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

curses.napms() aborts with a SystemError #126313

Closed
devdanzin opened this issue Nov 1, 2024 · 5 comments
Closed

curses.napms() aborts with a SystemError #126313

devdanzin opened this issue Nov 1, 2024 · 5 comments
Assignees
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@devdanzin
Copy link
Contributor

devdanzin commented Nov 1, 2024

Crash report

What happened?

The abort happens on normal and no-gil debug builds, release builds also hit the SystemError.

import curses
curses.napms(37)

Error is:

Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set
Python runtime state: initialized
_curses.error: must call initscr() first

The above exception was the direct cause of the following exception:

SystemError: <built-in function napms> returned a result with an exception set

Current thread 0x00007fe41a8c3740 (most recent call first):
  File "/home/fusil/python-73/curses-fatal/source.py", line 3 in <module>
Aborted

Found using fusil by @vstinner.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

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

Python 3.14.0a1+ experimental free-threading build (heads/main:d467d9246c, Nov 1 2024, 09:05:56) [GCC 11.4.0]

Linked PRs

@devdanzin devdanzin added the type-crash A hard crash of the interpreter, possibly with a core dump label Nov 1, 2024
@picnixz picnixz added the extension-modules C modules in the Modules dir label Nov 2, 2024
@picnixz
Copy link
Contributor

picnixz commented Nov 2, 2024

Ah I can see what happened. The macro returns 0 so that it can be used as a substitute for NULL in most of the functions it's being used but _curses.napms returns an int. Instead, it should return -1. It's an easy fix (one should simply remove the macro usage for this one and do something like that:

 if (!_PyCursesStatefulCheckFunction(module,
								     curses_initscr_called,
									 "initscr")) {
	return -1;
}

I think it should suffice. I won't make a PR on Saturday (UTC+2) but probably on Sunday.

@picnixz picnixz self-assigned this Nov 2, 2024
@picnixz picnixz changed the title curses.napms(37) aborts with a SystemError curses.napms() aborts with a SystemError Nov 2, 2024
@picnixz picnixz added 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Nov 3, 2024
@vstinner
Copy link
Member

vstinner commented Nov 4, 2024

Fixed by change 19d9358.

@serhiy-storchaka
Copy link
Member

The fix was not backported yet.

@picnixz
Copy link
Contributor

picnixz commented Nov 6, 2024

Update: No need for a 3.12 backport because the implementation returns a PyObject * instead of an int. Only a 3.13 backport is needed (which I am taking care of now).

picnixz added a commit to picnixz/cpython that referenced this issue Nov 6, 2024
@picnixz picnixz removed the 3.12 bugs and security fixes label Nov 6, 2024
vstinner pushed a commit that referenced this issue Nov 6, 2024
…r handling (GH-126351) (#126493)

gh-126313: Fix a crash in curses.napms() due to incorrect error handling (GH-126351)
@vstinner
Copy link
Member

vstinner commented Nov 6, 2024

I merged the 3.13 backport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
Projects
Status: Done
Development

No branches or pull requests

4 participants