* gettext-tools/src/x-scheme.c: Include error-progname.h.
(MAX_NESTING_DEPTH): New macro.
(nesting_depth): New variable.
(read_object): Increase nesting_depth before calling read_object recursively.
Check nesting_depth.
(extract_scheme): Initialize nesting_depth.
* gettext-tools/tests/xgettext-scheme-stackovfl-1: New file.
* gettext-tools/tests/xgettext-scheme-stackovfl-2: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add them.
/* xgettext Scheme backend.
- Copyright (C) 2004-2009, 2011, 2014, 2018-2020 Free Software Foundation, Inc.
+ Copyright (C) 2004-2009, 2011, 2014, 2018-2023 Free Software Foundation, Inc.
This file was written by Bruno Haible <bruno@clisp.org>, 2004-2005.
#include "xg-arglist-parser.h"
#include "xg-message.h"
#include "error.h"
+#include "error-progname.h"
#include "xalloc.h"
#include "mem-hash-map.h"
#include "gettext.h"
return str;
}
+
/* Context lookup table. */
static flag_context_list_table_ty *flag_context_list_table;
+
+/* Maximum supported nesting depth. */
+#define MAX_NESTING_DEPTH 1000
+
+/* Current nesting depth. */
+static int nesting_depth;
+
+
/* Read the next object. */
static void
read_object (struct object *op, flag_context_ty outer_context)
{
+ if (nesting_depth > MAX_NESTING_DEPTH)
+ {
+ error_with_progname = false;
+ error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested objects"),
+ logical_file_name, line_number);
+ }
for (;;)
{
int c = do_getc ();
flag_context_list_iterator_advance (
&context_iter));
+ ++nesting_depth;
read_object (&inner, inner_context);
+ nesting_depth--;
/* Recognize end of list. */
if (inner.type == t_close)
{
struct object inner;
+ ++nesting_depth;
read_object (&inner, null_context);
+ nesting_depth--;
/* Dots and EOF are not allowed here. But be tolerant. */
do_ungetc (c);
{
struct object inner;
+ ++nesting_depth;
read_object (&inner, null_context);
+ nesting_depth--;
/* Dots and EOF are not allowed here.
But be tolerant. */
free_object (&inner);
#y(...) - vector of byte (old)
*/
struct object inner;
+ ++nesting_depth;
read_object (&inner, null_context);
+ nesting_depth--;
/* Dots and EOF are not allowed here.
But be tolerant. */
free_token (&token);
#i(...) - vector of double-float (old)
*/
struct object inner;
+ ++nesting_depth;
read_object (&inner, null_context);
+ nesting_depth--;
/* Dots and EOF are not allowed here.
But be tolerant. */
free_token (&token);
case ',': /* srfi-10.scm */
{
struct object inner;
+ ++nesting_depth;
read_object (&inner, null_context);
+ nesting_depth--;
/* Dots and EOF are not allowed here.
But be tolerant. */
free_object (&inner);
last_non_comment_line = -1;
flag_context_list_table = flag_table;
+ nesting_depth = 0;
init_keywords ();
xgettext-ruby-1 \
xgettext-scheme-1 xgettext-scheme-2 xgettext-scheme-3 \
xgettext-scheme-4 \
+ xgettext-scheme-stackovfl-1 xgettext-scheme-stackovfl-2 \
xgettext-sh-1 xgettext-sh-2 xgettext-sh-3 xgettext-sh-4 xgettext-sh-5 \
xgettext-sh-6 xgettext-sh-7 \
xgettext-smalltalk-1 xgettext-smalltalk-2 \
--- /dev/null
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test Scheme support: stack overflow prevented by nesting depth check.
+
+cat <<EOF > xg-sc-so-1.scm
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+(((((((((((((((((((((((((((((((((((((((((((((((((
+(_ "Hello!")
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+)))))))))))))))))))))))))))))))))))))))))))))))))
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} -k_ --omit-header --no-location -d xg-sc-so-1.tmp xg-sc-so-1.scm || Exit 1
+LC_ALL=C tr -d '\r' < xg-sc-so-1.tmp.po > xg-sc-so-1.po || Exit 1
+
+cat <<EOF > xg-sc-so-1.ok
+msgid "Hello!"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-sc-so-1.ok xg-sc-so-1.po
+result=$?
+
+exit $result
--- /dev/null
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test Scheme support: stack overflow prevented by nesting depth check.
+
+cat <<EOF > xg-sc-so-2.scm
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+(_ "Hello!")
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} -k_ --omit-header --no-location -d xg-sc-so-2.tmp xg-sc-so-2.scm 2>xg-sc-so-2.err
+result=$?
+cat xg-sc-so-2.err
+test $result = 1 || Exit 1
+
+exit 0