Hello, cal utility segfaults in putp() when setupterm() fails as cal insufficiently checks for setupterm() failure. $ TERM= cal Segmentation fault Please find details in https://bugzilla.suse.com/show_bug.cgi?id=903440 especially in comment 4. Petr
Index: misc-utils/cal.c =================================================================== --- misc-utils/cal.c.orig 2014-08-26 16:48:45.132654654 +0200 +++ misc-utils/cal.c 2015-03-11 14:16:06.075064939 +0100 @@ -81,14 +81,22 @@ # endif # include <term.h> -static void my_setupterm(const char *term, int fildes, int *errret) +#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP) +static const char *term=""; +#endif + +static int my_setupterm(const char *term, int fildes) { - setupterm((char *)term, fildes, errret); + int errret; /* unused */ + return setupterm((char *)term, fildes, &errret) == OK; } static void my_putstring(char *s) { - putp(s); + if (term) + putp(s); + else + fputs(s, stdout); } static const char *my_tgetstr(char *s __attribute__((__unused__)), char *ss) @@ -107,9 +115,9 @@ static char tcbuffer[4096]; static char *strbuf = termbuffer; -static void my_setupterm(const char *term, int fildes __attribute__((__unused__)), int *errret) +static int my_setupterm(const char *term, int fildes __attribute__((__unused__))) { - *errret = tgetent(tcbuffer, term); + return tgetent(tcbuffer, term) == 1; } static void my_putstring(char *s) @@ -135,10 +143,6 @@ #endif /* end of LIBTERMCAP / NCURSES */ -#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP) -static const char *term=""; -#endif - static const char *Senter="", *Sexit="";/* enter and exit standout mode */ #include "widechar.h" @@ -293,12 +297,14 @@ #if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP) if ((term = getenv("TERM"))) { - int ret; - my_setupterm(term, STDOUT_FILENO, &ret); - if (ret > 0) { + if (my_setupterm(term, STDOUT_FILENO)) { Senter = my_tgetstr("so","smso"); Sexit = my_tgetstr("se","rmso"); } + else + { + term = NULL; + } } #endif
Attachment:
signature.asc
Description: Digital signature