]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
New test against stack overflow.
authorBruno Haible <bruno@clisp.org>
Fri, 16 Nov 2007 02:52:04 +0000 (02:52 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:33 +0000 (12:15 +0200)
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/gettext-8-prg.c [new file with mode: 0644]

index b375234c2c3c5095f8bbcca9aad416cfa6a02c53..d048b214d4d8405a8ac973c901c98dc464663130 100644 (file)
@@ -1,3 +1,9 @@
+2007-11-15  Bruno Haible  <bruno@clisp.org>
+
+       * gettext-8-prg.c: New file.
+       * Makefile.am (TESTS, noinst_PROGRAMS): Add gettext-8.
+       (gettext_8_*): New variables.
+
 2007-11-07  Bruno Haible  <bruno@clisp.org>
 
        * gettext-0.17 released.
index 6be566cf6482ee649083158580993640c807c15c..ebd03f9cb1458d6264cefc6ff83c17223ceb3efe 100644 (file)
@@ -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 (file)
index 0000000..a5e1513
--- /dev/null
@@ -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 <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;
+}