From: Bruno Haible Date: Thu, 14 Dec 2006 12:36:22 +0000 (+0000) Subject: NetBSD doesn't support tgetstr(...,NULL). X-Git-Tag: v0.17~588 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1173b04b0f53e951550189f5be627cbd63f38c15;p=thirdparty%2Fgettext.git NetBSD doesn't support tgetstr(...,NULL). --- diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index 26b8e7fd5..7ddc86459 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -1,3 +1,9 @@ +2006-12-13 Bruno Haible + + Avoid crash on NetBSD. + * lib/term-ostream.oo.c (term_ostream_create): Pass a non-NULL area + pointer to tgetstr. + 2006-12-13 Bruno Haible * lib/tparm.c: New file, based on a public-domain implementation part diff --git a/gnulib-local/lib/term-ostream.oo.c b/gnulib-local/lib/term-ostream.oo.c index e919cbe47..11918b030 100644 --- a/gnulib-local/lib/term-ostream.oo.c +++ b/gnulib-local/lib/term-ostream.oo.c @@ -1694,7 +1694,9 @@ 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); @@ -1703,20 +1705,26 @@ 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", NULL)); - stream->set_foreground = xstrdup0 (tgetstr ("Sf", NULL)); - stream->set_a_background = xstrdup0 (tgetstr ("AB", NULL)); - stream->set_background = xstrdup0 (tgetstr ("Sb", NULL)); - stream->orig_pair = xstrdup0 (tgetstr ("op", NULL)); - stream->enter_bold_mode = xstrdup0 (tgetstr ("md", NULL)); - stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", NULL)); - stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", NULL)); - stream->enter_underline_mode = xstrdup0 (tgetstr ("us", NULL)); - stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", NULL)); - stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", NULL)); + 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 @@ -1735,6 +1743,12 @@ term_ostream_create (int fd, const char *filename) 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 (); } /* Infer the capabilities. */