Skip to content

Crash in _curses when calling .initscr() after ignoring exception from .resizeterm() #122398

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

Closed
devdanzin opened this issue Jul 29, 2024 · 2 comments
Labels
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 Jul 29, 2024

Crash report

What happened?

Running this test script segfaults on main, with the following backtrace.
$ ./python test.py
test.py:

import _curses
_curses.initscr()
try:
    _curses.resizeterm(40000, 40000)
except:
    pass
_curses.initscr()
#0  0x00007ffff79985aa in ?? () from /lib/x86_64-linux-gnu/libncursesw.so.6
#1  0x00007ffff799ad0a in doupdate_sp () from /lib/x86_64-linux-gnu/libncursesw.so.6
#2  0x00007ffff798e6d8 in wrefresh () from /lib/x86_64-linux-gnu/libncursesw.so.6
#3  0x00007ffff79ce89f in _curses_initscr_impl (module=<optimized out>) at ./Modules/_cursesmodule.c:3272
#4  0x00007ffff79cf62f in _curses_initscr (module=<optimized out>, _unused_ignored=<optimized out>)
    at ./Modules/clinic/_cursesmodule.c.h:2661
#5  0x00005555556fb6e9 in cfunction_vectorcall_NOARGS (func=0x7ffff7ac7fb0, args=<optimized out>,
    nargsf=<optimized out>, kwnames=<optimized out>) at Objects/methodobject.c:484

Seems fixable by setting initialised to FALSE in _curses_resizeterm_impl for the error paths, not sure this is a valid fix:

diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index b5854e8c33f..10f1c4b14c5 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -4106,9 +4106,12 @@ _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
     PyCursesInitialised;

     result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");
-    if (!result)
+    if (!result) {
+        initialised = FALSE;
         return NULL;
+    }
     if (!update_lines_cols()) {
+        initialised = FALSE;
         Py_DECREF(result);
         return NULL;
     }

Found in pypy/pypy#4989.

CPython versions tested on:

3.11, CPython main branch

Operating systems tested on:

Linux

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

Python 3.14.0a0 (heads/main:9187484dd97, Jul 29 2024, 09:25:22) [GCC 11.4.0]

@devdanzin devdanzin added the type-crash A hard crash of the interpreter, possibly with a core dump label Jul 29, 2024
@devdanzin
Copy link
Contributor Author

Also crashes with resize_term(40000, 40000).

@Eclips4 Eclips4 added the extension-modules C modules in the Modules dir label Jul 29, 2024
@devdanzin
Copy link
Contributor Author

This is a duplicate of #120378.

@devdanzin devdanzin closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

2 participants