diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-12-24 07:38:37 +0000 |
---|---|---|
committer | <> | 2015-02-02 12:02:29 +0000 |
commit | 482840e61f86ca321838a91e902c41d40c098bbb (patch) | |
tree | 01ea2e242fd2792d19fe192476601587901db794 /gettext-tools/tests/gettext-8-prg.c | |
download | gettext-tarball-482840e61f86ca321838a91e902c41d40c098bbb.tar.gz |
Imported from /home/lorry/working-area/delta_gettext-tarball/gettext-0.19.4.tar.xz.gettext-0.19.4
Diffstat (limited to 'gettext-tools/tests/gettext-8-prg.c')
-rw-r--r-- | gettext-tools/tests/gettext-8-prg.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/gettext-tools/tests/gettext-8-prg.c b/gettext-tools/tests/gettext-8-prg.c new file mode 100644 index 0000000..7edd016 --- /dev/null +++ b/gettext-tools/tests/gettext-8-prg.c @@ -0,0 +1,83 @@ +/* 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> +#include <assert.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; + char *translated; + + 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'; + + translated = gettext (msg); + free (msg); + assert (translated != NULL); + + return 0; +} |