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 \
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)
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
--- /dev/null
+/* 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 <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <haible@clisp.cons.org>, 2007. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if HAVE_GETRLIMIT && HAVE_SETRLIMIT
+# include <sys/types.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+#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;
+}