summaryrefslogtreecommitdiffstats
path: root/curs_ti_lib.c
AgeCommit message (Collapse)Author
2021-12-27Include <term.h> before invoking tigetstr() and tigetflag().Kevin McCarthy
On NetBSD, a segv was occurring in mutt_ts_capability() because tigetstr() was implicitly declared and thus defaulted to return type int. The 8-byte (char *) actually returned was being converted to a 4-byte int before being assigned to the (char *) variable. This resulted in a corrupted pointer, causing a segv when dereferenced. I thought C99+ should warn about implicit declarations. Although configure.ac AC_PROG_CC_C99 asserts the compiler can handle C99, perhaps it doesn't put the compiler in the mode to strictly enforce it. (Thanks to rkta on IRC for the input). The solution, as the man page notes, is to include <term.h> before invoking those functions. Unfortunately term.h pollutes the namespace with all sorts of defines. Currently that include columns and lines, which are used inside Mutt. To help prevent issues, create Mutt wrappers for the functions and split them into a separate file, curs_ti_lib.c, that #include <term.h>, rather than just adding #include <term.h> to mutt_curses.h Apparently on some older platforms, #include <curses.h> would also include term.h, so make sure columns in undef'ed in mutt_curses.h. (I think we would have heard about that problem already, but just in case.) A huge thank you to rahl on IRC for debugging this issue, and working with me over IRC to test various suggestions until the issue was found. I didn't have access to a NetBSD instance, so rahl saved me much time and effort, and was crucial to fixing this bug.