pwntools icon indicating copy to clipboard operation
pwntools copied to clipboard

`curses.setupterm` error when $TERM is unset

Open unprintable123 opened this issue 1 year ago • 2 comments

This issue https://github.com/Gallopsled/pwntools/issues/1658 returned after upgrading colored_traceback.

root@123-computer:~# PWNLIB_NOTERM=1 sage -c 'import pwn'
Traceback (most recent call last):
  File "/home/sceleri/sage/src/bin/sage-eval", line 10, in <module>
    eval(compile(s,'<cmdline>','exec'))
  File "<cmdline>", line 1, in <module>
  File "/home/sceleri/sage/local/var/lib/sage/venv-python3.12.5/lib/python3.12/site-packages/pwn/__init__.py", line 4, in <module>
    from pwn.toplevel import *
  File "/home/sceleri/sage/local/var/lib/sage/venv-python3.12.5/lib/python3.12/site-packages/pwn/toplevel.py", line 92, in <module>
    colored_traceback.add_hook()
  File "/home/sceleri/sage/local/var/lib/sage/venv-python3.12.5/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 78, in add_hook
    colorizer = Colorizer(style, colors, debug)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sceleri/sage/local/var/lib/sage/venv-python3.12.5/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 64, in __init__
    self.formatter = _determine_formatter(style, colors, debug)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sceleri/sage/local/var/lib/sage/venv-python3.12.5/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 38, in _determine_formatter
    colors = colors or _get_term_color_support()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sceleri/sage/local/var/lib/sage/venv-python3.12.5/lib/python3.12/site-packages/colored_traceback/colored_traceback.py", line 34, in _get_term_color_support
    curses.setupterm()
_curses.error: setupterm: could not find terminfo database

Also see https://github.com/sagemath/sage/issues/39334

unprintable123 avatar Jul 29 '25 02:07 unprintable123

This should be fixed in colored_traceback, have you reported this there too? We could try to work around it by not enabling colored traceback if our own terminal stuff is disabled?

peace-maker avatar Jul 29 '25 09:07 peace-maker

IMO the real problem is curses.setupterm fails when TERM is unset. But in python document it seems to be an expected behavior. colored_traceback just somehow catches the error in the previous version.

I think we should try to work around it like #L56-L64 does.

unprintable123 avatar Jul 29 '25 10:07 unprintable123