From: Bruno Haible Date: Fri, 16 Nov 2007 02:52:04 +0000 (+0000) Subject: New test against stack overflow. X-Git-Tag: v0.18~495 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a37c64bd6b382658e48a0ab6493242a5444126d;p=thirdparty%2Fgettext.git New test against stack overflow. --- diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index b375234c2..d048b214d 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,9 @@ +2007-11-15 Bruno Haible + + * gettext-8-prg.c: New file. + * Makefile.am (TESTS, noinst_PROGRAMS): Add gettext-8. + (gettext_8_*): New variables. + 2007-11-07 Bruno Haible * gettext-0.17 released. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 6be566cf6..ebd03f9cb 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -21,6 +21,7 @@ EXTRA_DIST = MOSTLYCLEANFILES = core *.stackdump TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ + gettext-8 \ msgattrib-1 msgattrib-2 msgattrib-3 msgattrib-4 msgattrib-5 \ msgattrib-6 msgattrib-7 msgattrib-8 msgattrib-9 msgattrib-10 \ msgattrib-11 msgattrib-12 msgattrib-13 msgattrib-14 msgattrib-15 \ @@ -199,7 +200,7 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ LDADD = $(LDADD_@USE_INCLUDED_LIBINTL@) @INTL_MACOSX_LIBS@ LDADD_yes = ../intl/libintl.la @LTLIBTHREAD@ LDADD_no = ../intl/libgnuintl.la @LTLIBTHREAD@ @LTLIBINTL@ -noinst_PROGRAMS = tstgettext tstngettext testlocale gettext-3-prg gettext-4-prg gettext-5-prg gettext-6-prg gettext-7-prg cake fc3 fc4 fc5 +noinst_PROGRAMS = tstgettext tstngettext testlocale gettext-3-prg gettext-4-prg gettext-5-prg gettext-6-prg gettext-7-prg gettext-8 cake fc3 fc4 fc5 tstgettext_SOURCES = tstgettext.c setlocale.c tstgettext_CFLAGS = -DINSTALLDIR=\".\" tstgettext_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) @@ -223,6 +224,8 @@ gettext_7_prg_CFLAGS = $(gettext_7_prg_CFLAGS_@GLIBC2@) gettext_7_prg_CFLAGS_yes = -DUSE_POSIX_THREADS gettext_7_prg_LDADD = $(gettext_7_prg_LDADD_@GLIBC2@) gettext_7_prg_LDADD_yes = ../gnulib-lib/libgettextlib.la $(LDADD) -lpthread +gettext_8_SOURCES = gettext-8-prg.c +gettext_8_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) cake_SOURCES = plural-1-prg.c setlocale.c cake_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) fc3_SOURCES = format-c-3-prg.c setlocale.c diff --git a/gettext-tools/tests/gettext-8-prg.c b/gettext-tools/tests/gettext-8-prg.c new file mode 100644 index 000000000..a5e151308 --- /dev/null +++ b/gettext-tools/tests/gettext-8-prg.c @@ -0,0 +1,79 @@ +/* Test that gettext() does not crash by stack overflow when msgid is very long. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2007. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include + +#if HAVE_GETRLIMIT && HAVE_SETRLIMIT +# include +# include +# include +#endif + +/* Make sure we use the included libintl, not the system's one. */ +#undef _LIBINTL_H +#include "libgnuintl.h" + +int +main () +{ + size_t n; + char *msg; + + n = 1000000; + +#if HAVE_GETRLIMIT && HAVE_SETRLIMIT + { + struct rlimit limit; + +# ifdef RLIMIT_STACK + if (getrlimit (RLIMIT_STACK, &limit) < 0) + { + printf ("Skipping test: getrlimit does not work\n"); + return 77; + } + if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > n) + limit.rlim_max = n; + limit.rlim_cur = limit.rlim_max; + if (setrlimit (RLIMIT_STACK, &limit) < 0) + { + printf ("Skipping test: setrlimit does not work\n"); + return 77; + } +# endif + } +#endif + + msg = (char *) malloc (n + 1); + if (msg == NULL) + { + printf ("Skipping test: out of memory\n"); + return 77; + } + memset (msg, 'x', n); + msg[n] = '\0'; + + msg = gettext (msg); + + return 0; +}