summaryrefslogtreecommitdiffstats
path: root/mutt_curses.h
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2021-12-26 15:43:27 -0800
committerKevin McCarthy <kevin@8t8.us>2021-12-27 12:15:18 -0800
commitc74cbba75016b4b7505624ea9ec6076dd97e4610 (patch)
tree985821cd128558253912c49e28a7ae8c7b7dbb15 /mutt_curses.h
parentf58795c9ddf354eb7bb0412decb894fae3a19571 (diff)
Include <term.h> before invoking tigetstr() and tigetflag().
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.
Diffstat (limited to 'mutt_curses.h')
-rw-r--r--mutt_curses.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/mutt_curses.h b/mutt_curses.h
index 9c57269b..0b49df19 100644
--- a/mutt_curses.h
+++ b/mutt_curses.h
@@ -57,13 +57,18 @@
#endif /* USE_SLANG_CURSES */
-/* AIX defines ``lines'' in <term.h>, but it's used as a var name in
- * various places in Mutt
+/* Some older platforms include <term.h> when curses.h is included.
+ * ``lines'' and ``columns'' are #defined there, but are also used
+ * as a var name in various places in Mutt.
*/
#ifdef lines
#undef lines
#endif /* lines */
+#ifdef columns
+#undef columns
+#endif /* columns */
+
#define CLEARLINE(win,x) mutt_window_clearline(win, x)
#define CENTERLINE(win,x,y) mutt_window_move(win, y, (win->cols-strlen(x))/2), addstr(x)
#define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
@@ -267,4 +272,8 @@ static inline void ATTRSET (const COLOR_ATTR X)
/* reset the color to the normal terminal color as defined by 'color normal ...' */
#define NORMAL_COLOR SETCOLOR(MT_COLOR_NORMAL)
+/* curs_ti_lib.c routines: */
+const char *mutt_tigetstr (const char *capname);
+int mutt_tigetflag (const char *capname);
+
#endif /* _MUTT_CURSES_H_ */