summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gettext-tools/src/x-vala.c17
-rw-r--r--gettext-tools/tests/Makefile.am1
-rwxr-xr-xgettext-tools/tests/xgettext-vala-stackovfl-163
-rwxr-xr-xgettext-tools/tests/xgettext-vala-stackovfl-256
4 files changed, 136 insertions, 1 deletions
diff --git a/gettext-tools/src/x-vala.c b/gettext-tools/src/x-vala.c
index e2754f73d..c26fc9673 100644
--- a/gettext-tools/src/x-vala.c
+++ b/gettext-tools/src/x-vala.c
@@ -1,5 +1,5 @@
/* xgettext Vala backend.
- Copyright (C) 2013-2014, 2018-2020 Free Software Foundation, Inc.
+ Copyright (C) 2013-2014, 2018-2023 Free Software Foundation, Inc.
This file was written by Daiki Ueno <ueno@gnu.org>, 2013.
@@ -1203,6 +1203,13 @@ x_vala_lex (token_ty *tp)
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;
+
+
/* The file is broken into tokens. Scan the token stream, looking for
a keyword, followed by a left paren, followed by a string. When we
see this sequence, we have something to remember. We assume we are
@@ -1277,6 +1284,12 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
continue;
case token_type_lparen:
+ if (++nesting_depth > MAX_NESTING_DEPTH)
+ {
+ error_with_progname = false;
+ error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
+ logical_file_name, line_number);
+ }
if (extract_balanced (mlp, token_type_rparen,
inner_context, next_context_iter,
arglist_parser_alloc (mlp,
@@ -1285,6 +1298,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
arglist_parser_done (argparser, arg);
return true;
}
+ nesting_depth--;
next_context_iter = null_context_list_iterator;
state = 0;
break;
@@ -1402,6 +1416,7 @@ extract_vala (FILE *f,
last_token_type = token_type_other;
flag_context_list_table = flag_table;
+ nesting_depth = 0;
init_keywords ();
diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am
index 89751fbc8..1cad63813 100644
--- a/gettext-tools/tests/Makefile.am
+++ b/gettext-tools/tests/Makefile.am
@@ -149,6 +149,7 @@ TESTS = gettext-1 gettext-2 \
xgettext-stringtable-1 \
xgettext-tcl-1 xgettext-tcl-2 xgettext-tcl-3 xgettext-tcl-4 \
xgettext-vala-1 xgettext-vala-2 \
+ xgettext-vala-stackovfl-1 xgettext-vala-stackovfl-2 \
xgettext-ycp-1 xgettext-ycp-2 xgettext-ycp-3 xgettext-ycp-4 \
format-awk-1 format-awk-2 \
format-boost-1 format-boost-2 \
diff --git a/gettext-tools/tests/xgettext-vala-stackovfl-1 b/gettext-tools/tests/xgettext-vala-stackovfl-1
new file mode 100755
index 000000000..9894418b1
--- /dev/null
+++ b/gettext-tools/tests/xgettext-vala-stackovfl-1
@@ -0,0 +1,63 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test Vala support: stack overflow prevented by nesting depth check.
+
+cat <<EOF > xg-vala-so-1.vala
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+(((((((((((((((((((((((((((((((((((((((((((((((((
+_("Hello!")
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+)))))))))))))))))))))))))))))))))))))))))))))))))
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --omit-header --no-location -d xg-vala-so-1.tmp xg-vala-so-1.vala || Exit 1
+LC_ALL=C tr -d '\r' < xg-vala-so-1.tmp.po > xg-vala-so-1.po || Exit 1
+
+cat <<EOF > xg-vala-so-1.ok
+msgid "Hello!"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-vala-so-1.ok xg-vala-so-1.po
+result=$?
+
+exit $result
diff --git a/gettext-tools/tests/xgettext-vala-stackovfl-2 b/gettext-tools/tests/xgettext-vala-stackovfl-2
new file mode 100755
index 000000000..44121b995
--- /dev/null
+++ b/gettext-tools/tests/xgettext-vala-stackovfl-2
@@ -0,0 +1,56 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test Vala support: stack overflow prevented by nesting depth check.
+
+cat <<EOF > xg-vala-so-2.vala
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((
+_("Hello!")
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --omit-header --no-location -d xg-vala-so-2.tmp xg-vala-so-2.vala 2>xg-vala-so-2.err
+result=$?
+cat xg-vala-so-2.err
+test $result = 1 || Exit 1
+
+exit 0