From: Petr Gajdos <pgajdos@suse.cz>
To: util-linux@vger.kernel.org
Subject: prevent cal segfault
Date: Thu, 12 Mar 2015 09:46:39 +0100 [thread overview]
Message-ID: <20150312084639.GC9756@laura.suse.cz> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 273 bytes --]
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
[-- Attachment #1.2: util-linux-cal-no-terminal.patch --]
[-- Type: text/x-patch, Size: 1979 bytes --]
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 #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next reply other threads:[~2015-03-12 8:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-12 8:46 Petr Gajdos [this message]
2015-03-12 9:10 ` prevent cal segfault Ruediger Meier
2015-03-12 11:05 ` Karel Zak
2015-03-12 12:00 ` Petr Gajdos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150312084639.GC9756@laura.suse.cz \
--to=pgajdos@suse.cz \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox