NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/56298: libcurses: assertion failure when $TERM lacks certain terminfo capabilities



>Number:         56298
>Category:       lib
>Synopsis:       libcurses: assertion failure when $TERM lacks certain terminfo capabilities
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 04 07:35:00 +0000 2021
>Originator:     Michael Forney
>Release:        
>Organization:
>Environment:
>Description:
If libcurses is built with -D_DIAGNOSTIC, assertion failures are triggered in the ti_puts family of functions when the terminal lacks certain capabilities since they are called with str==NULL. In particular, this happens with TERM=linux.

Here are a couple of problematic codepaths:

libcurses/tty.c:__startwin:577: ti_puts(screen->term, t_enter_ca_mode(screen->term), 0, __cputchar_args, (void *) screen->outfd);
libterminfo/tputs:ti_puts:138: _DIAGASSERT(str != NULL);

If term has no smcup, t_enter_ca_mode returns NULL and the assert fails.

libcurses/keypad.c:keypad:52: tputs(keypad_xmit, 0, __cputchar);
libterminfo/tputs.c:tputs:167: _DIAGASSERT(str != NULL);

If term has no smkx, keypad_xmit evaluates to NULL and the assert fails.

The _ti_puts function is the base implementation for all these functions, and it handles str==NULL just fine by returning OK immediately. So it seems that these _DIAGASSERTs are unnecessary and should be removed.
>How-To-Repeat:
Build libcurses with -D_DIAGNOSTIC, then run a program using libcurses that calls newterm() and keypad() (such as the vis text editor).
>Fix:
I think the problematic assertions should be removed:

diff --git a/lib/libterminfo/tputs.c b/lib/libterminfo/tputs.c
index f1e15bbc613c..aa2118da6dc9 100644
--- a/lib/libterminfo/tputs.c
+++ b/lib/libterminfo/tputs.c
@@ -135,7 +135,6 @@ ti_puts(const TERMINAL *term, const char *str, int affcnt,
 	char pc;
 
 	_DIAGASSERT(term != NULL);
-	_DIAGASSERT(str != NULL);
 	_DIAGASSERT(outc != NULL);
 
 	dodelay = (str == t_bell(term) ||
@@ -155,7 +154,6 @@ ti_putp(const TERMINAL *term, const char *str)
 {
 
 	_DIAGASSERT(term != NULL);
-	_DIAGASSERT(str != NULL);
 	return ti_puts(term, str, 1,
 	    (int (*)(int, void *))(void *)putchar, NULL);
 }
@@ -164,7 +162,6 @@ int
 tputs(const char *str, int affcnt, int (*outc)(int))
 {
 
-	_DIAGASSERT(str != NULL);
 	_DIAGASSERT(outc != NULL);
 	return _ti_puts(1, ospeed, PC, str, affcnt,
 	    (int (*)(int, void *))(void *)outc, NULL);
@@ -174,6 +171,5 @@ int
 putp(const char *str)
 {
 
-	_DIAGASSERT(str != NULL);
 	return tputs(str, 1, putchar);
 }



Home | Main Index | Thread Index | Old Index