From: Bruno Haible Date: Mon, 18 Dec 2006 12:03:31 +0000 (+0000) Subject: tgetent may fail. X-Git-Tag: v0.17~578 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a16acdd1bca820228809fd4e24ae95cb5db631f0;p=thirdparty%2Fgettext.git tgetent may fail. --- diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index 6a422585b..7456380d2 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -1,3 +1,8 @@ +2006-12-16 Bruno Haible + + * lib/term-ostream.oo.c (term_ostream_create): Don't ignore tgetent's + return value. + 2006-12-16 Bruno Haible * lib/libcroco/cr-style.h (enum CRPositionType): Remove trailing diff --git a/gnulib-local/lib/term-ostream.oo.c b/gnulib-local/lib/term-ostream.oo.c index 11918b030..ed524db62 100644 --- a/gnulib-local/lib/term-ostream.oo.c +++ b/gnulib-local/lib/term-ostream.oo.c @@ -1694,9 +1694,7 @@ term_ostream_create (int fd, const char *filename) if (term != NULL && term[0] != '\0') { struct { char buf[1024]; char canary[4]; } termcapbuf; - struct { char buf[1024]; char canary[4]; } termentrybuf; int retval; - char *termentryptr; /* Call tgetent, being defensive against buffer overflow. */ memcpy (termcapbuf.canary, "CnRy", 4); @@ -1705,50 +1703,56 @@ term_ostream_create (int fd, const char *filename) /* Buffer overflow! */ abort (); - /* Prepare for calling tgetstr, being defensive against buffer - overflow. ncurses' tgetstr() supports a second argument NULL, - but NetBSD's tgetstr() doesn't. */ - memcpy (termentrybuf.canary, "CnRz", 4); - #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr) - - /* Retrieve particular values depending on the terminal type. */ - stream->max_colors = tgetnum ("Co"); - stream->no_color_video = tgetnum ("nc"); - stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP)); - stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP)); - stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP)); - stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP)); - stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP)); - stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP)); - stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP)); - stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP)); - stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP)); - stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP)); - stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP)); + if (retval > 0) + { + struct { char buf[1024]; char canary[4]; } termentrybuf; + char *termentryptr; + + /* Prepare for calling tgetstr, being defensive against buffer + overflow. ncurses' tgetstr() supports a second argument NULL, + but NetBSD's tgetstr() doesn't. */ + memcpy (termentrybuf.canary, "CnRz", 4); + #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr) + + /* Retrieve particular values depending on the terminal type. */ + stream->max_colors = tgetnum ("Co"); + stream->no_color_video = tgetnum ("nc"); + stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP)); + stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP)); + stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP)); + stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP)); + stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP)); + stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP)); + stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP)); + stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP)); + stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP)); + stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP)); + stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP)); #ifdef __BEOS__ - /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB" it - contains balues in terminfo syntax but the system's tparam() function - understands only the termcap syntax. */ - if (stream->set_a_foreground != NULL - && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0) - { - free (stream->set_a_foreground); - stream->set_a_foreground = xstrdup ("\033[3%dm"); - } - if (stream->set_a_background != NULL - && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0) - { - free (stream->set_a_background); - stream->set_a_background = xstrdup ("\033[4%dm"); - } + /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB" + it contains balues in terminfo syntax but the system's tparam() + function understands only the termcap syntax. */ + if (stream->set_a_foreground != NULL + && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0) + { + free (stream->set_a_foreground); + stream->set_a_foreground = xstrdup ("\033[3%dm"); + } + if (stream->set_a_background != NULL + && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0) + { + free (stream->set_a_background); + stream->set_a_background = xstrdup ("\033[4%dm"); + } #endif - /* Done with tgetstr. Detect possible buffer overflow. */ - #undef TEBP - if (memcmp (termentrybuf.canary, "CnRz", 4) != 0) - /* Buffer overflow! */ - abort (); + /* Done with tgetstr. Detect possible buffer overflow. */ + #undef TEBP + if (memcmp (termentrybuf.canary, "CnRz", 4) != 0) + /* Buffer overflow! */ + abort (); + } } /* Infer the capabilities. */