summaryrefslogtreecommitdiff
path: root/gettext-tools/src
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-03-09 22:30:17 +0100
committerBruno Haible <bruno@clisp.org>2023-03-09 22:30:17 +0100
commite62ed464dca2c06eec7945375372b7e4dfdeeb03 (patch)
tree97c6e93acd44c727117e2d719374aec67b2b7e14 /gettext-tools/src
parent423572741811037a7a6f1127221aaf1fe6842aff (diff)
downloadgettext-e62ed464dca2c06eec7945375372b7e4dfdeeb03.tar.gz
xgettext: In language YCP, avoid stack overflow.
* gettext-tools/src/x-ycp.c: Include error-progname.h. (MAX_NESTING_DEPTH): New macro. (nesting_depth): New variable. (extract_parenthesized): Increase and check nesting_depth before calling extract_parenthesized recursively. (extract_ycp): Initialize nesting_depth. * gettext-tools/tests/xgettext-ycp-stackovfl-1: New file. * gettext-tools/tests/xgettext-ycp-stackovfl-2: New file. * gettext-tools/tests/xgettext-ycp-stackovfl-3: New file. * gettext-tools/tests/xgettext-ycp-stackovfl-4: New file. * gettext-tools/tests/Makefile.am (TESTS): Add them.
Diffstat (limited to 'gettext-tools/src')
-rw-r--r--gettext-tools/src/x-ycp.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/gettext-tools/src/x-ycp.c b/gettext-tools/src/x-ycp.c
index 4f6d16871..ab9749613 100644
--- a/gettext-tools/src/x-ycp.c
+++ b/gettext-tools/src/x-ycp.c
@@ -1,5 +1,5 @@
/* xgettext YCP backend.
- Copyright (C) 2001-2003, 2005-2009, 2011, 2018-2020 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2005-2009, 2011, 2018-2023 Free Software Foundation, Inc.
This file was written by Bruno Haible <haible@clisp.cons.org>, 2001.
@@ -37,6 +37,7 @@
#include "xg-arglist-context.h"
#include "xg-message.h"
#include "error.h"
+#include "error-progname.h"
#include "xalloc.h"
#include "gettext.h"
@@ -634,6 +635,13 @@ phase8_unget (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.
Normal handling: Look for
@@ -684,9 +692,16 @@ extract_parenthesized (message_list_ty *mlp,
switch (token.type)
{
case token_type_i18n:
+ 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_parenthesized (mlp, inner_context, next_context_iter,
true))
return true;
+ nesting_depth--;
next_context_iter = null_context_list_iterator;
state = 0;
continue;
@@ -752,9 +767,16 @@ extract_parenthesized (message_list_ty *mlp,
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_parenthesized (mlp, inner_context, next_context_iter,
false))
return true;
+ nesting_depth--;
next_context_iter = null_context_list_iterator;
state = 0;
continue;
@@ -811,6 +833,7 @@ extract_ycp (FILE *f,
phase8_pushback_length = 0;
flag_context_list_table = flag_table;
+ nesting_depth = 0;
/* Eat tokens until eof is seen. When extract_parenthesized returns
due to an unbalanced closing parenthesis, just restart it. */