forked from Imagelibrary/binutils-gdb
Synchronize libiberty with gcc and add --no-recruse-limit option to tools that support name demangling.
This patch addresses the multitude of bug reports about resource exhaustion
in libiberty's name demangling code. It adds a limit to the amount of
recursion that is allowed, before an error is triggered. It also adds a
new demangling option to disable this limit. (The limit is enabled by
default).
PR 87681
PR 87675
PR 87636
PR 87335
libiberty * cp-demangle.h (struct d_info): Add recursion_limit field.
* cp-demangle.c (d_function_type): If the recursion limit is
enabled and reached, return with a failure result.
(d_demangle_callback): If the recursion limit is enabled, check
for a mangled string that is so long that there is not enough
stack space for the local arrays.
* cplus-dem.c (struct work): Add recursion_level field.
(demangle_nested_args): If the recursion limit is enabled and
reached, return with a failure result.
include * demangle.h (DMGL_RECURSE_LIMIT): Define.
(DEMANGLE_RECURSION_LIMIT): Prototype.
binutuils * addr2line.c (demangle_flags): New static variable.
(long_options): Add --recurse-limit and --no-recurse-limit.
(translate_address): Pass demangle_flags to bfd_demangle.
(main): Handle --recurse-limit and --no-recurse-limit options.
* cxxfilt.c (flags): Add DMGL_RECURSE_LIMIT.
(long_options): Add --recurse-limit and --no-recurse-limit.
(main): Handle new options.
* dlltool.c (gen_def_file): Include DMGL_RECURSE_LIMIT in flags
passed to cplus_demangle.
* nm.c (demangle_flags): New static variable.
(long_options): Add --recurse-limit and --no-recurse-limit.
(main): Handle new options.
* objdump.c (demangle_flags): New static variable.
(usage): Add --recurse-limit and --no-recurse-limit.
(long_options): Likewise.
(objdump_print_symname): Pass demangle_flags to bfd_demangle.
(disassemble_section): Likewise.
(dump_dymbols): Likewise.
(main): Handle new options.
* prdbg.c (demangle_flags): New static variable.
(tg_variable): Pass demangle_flags to demangler.
(tg_start_function): Likewise.
* stabs.c (demangle_flags): New static variable.
(stab_demangle_template): Pass demangle_flags to demangler.
(stab_demangle_v3_argtypes): Likewise.
(stab_demangle_v3_arg): Likewise.
* doc/binutuls.texi: Document new command line options.
* NEWS: Mention the new feature.
* testsuite/config/default.exp (CXXFILT): Define if not already
defined.
(CXXFILTFLAGS): Likewise.
* testsuite/binutils-all/cxxfilt.exp: New file. Runs a few
simple tests of the cxxfilt program.
This commit is contained in:
@@ -45,6 +45,9 @@ static bfd_boolean do_demangle; /* -C, demangle names. */
|
||||
static bfd_boolean pretty_print; /* -p, print on one line. */
|
||||
static bfd_boolean base_names; /* -s, strip directory names. */
|
||||
|
||||
/* Flags passed to the name demangler. */
|
||||
static int demangle_flags = DMGL_PARAMS | DMGL_ANSI;
|
||||
|
||||
static int naddr; /* Number of addresses to process. */
|
||||
static char **addr; /* Hex addresses to process. */
|
||||
|
||||
@@ -59,6 +62,10 @@ static struct option long_options[] =
|
||||
{"functions", no_argument, NULL, 'f'},
|
||||
{"inlines", no_argument, NULL, 'i'},
|
||||
{"pretty-print", no_argument, NULL, 'p'},
|
||||
{"recurse-limit", no_argument, NULL, 'R'},
|
||||
{"recursion-limit", no_argument, NULL, 'R'},
|
||||
{"no-recurse-limit", no_argument, NULL, 'r'},
|
||||
{"no-recursion-limit", no_argument, NULL, 'r'},
|
||||
{"section", required_argument, NULL, 'j'},
|
||||
{"target", required_argument, NULL, 'b'},
|
||||
{"help", no_argument, NULL, 'H'},
|
||||
@@ -91,6 +98,8 @@ usage (FILE *stream, int status)
|
||||
-s --basenames Strip directory names\n\
|
||||
-f --functions Show function names\n\
|
||||
-C --demangle[=style] Demangle function names\n\
|
||||
-R --recurse-limit Enable a limit on recursion whilst demangling. [Default]\n\
|
||||
-r --no-recurse-limit Disable a limit on recursion whilst demangling\n\
|
||||
-h --help Display this information\n\
|
||||
-v --version Display the program's version\n\
|
||||
\n"));
|
||||
@@ -289,7 +298,7 @@ translate_addresses (bfd *abfd, asection *section)
|
||||
name = "??";
|
||||
else if (do_demangle)
|
||||
{
|
||||
alloc = bfd_demangle (abfd, name, DMGL_ANSI | DMGL_PARAMS);
|
||||
alloc = bfd_demangle (abfd, name, demangle_flags);
|
||||
if (alloc != NULL)
|
||||
name = alloc;
|
||||
}
|
||||
@@ -442,7 +451,7 @@ main (int argc, char **argv)
|
||||
file_name = NULL;
|
||||
section_name = NULL;
|
||||
target = NULL;
|
||||
while ((c = getopt_long (argc, argv, "ab:Ce:sfHhij:pVv", long_options, (int *) 0))
|
||||
while ((c = getopt_long (argc, argv, "ab:Ce:rRsfHhij:pVv", long_options, (int *) 0))
|
||||
!= EOF)
|
||||
{
|
||||
switch (c)
|
||||
@@ -469,6 +478,12 @@ main (int argc, char **argv)
|
||||
cplus_demangle_set_style (style);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
demangle_flags |= DMGL_NO_RECURSE_LIMIT;
|
||||
break;
|
||||
case 'R':
|
||||
demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT;
|
||||
break;
|
||||
case 'e':
|
||||
file_name = optarg;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user