Ghidra is a software reverse engineering (SRE) framework
GT-3481 - Gnu Demangler - Updated v2.24 to use prevent known segmentation fault
dragonmacherb6fb46f5df7a
diff --git a/GPL/DemanglerGnu/build.gradle b/GPL/DemanglerGnu/build.gradleindex 79658075cf..a2eea61048 100644--- a/GPL/DemanglerGnu/build.gradle+++ b/GPL/DemanglerGnu/build.gradle@@ -145,7 +145,8 @@ model {println "have binary: " + bif (version.equals(v33_1)) {- if (toolChain in Gcc) {+ if (toolChain in Gcc) {+ //cCompiler.args "-DCP_DEMANGLE_DEBUG"cCompiler.args "-DHAVE_STDLIB_H"cCompiler.args "-DHAVE_STRING_H"}diff --git a/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/cp-demangle.c b/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/cp-demangle.cindex 2ea476ae3b..236da39db0 100644--- a/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/cp-demangle.c+++ b/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/cp-demangle.c@@ -33,7 +33,9 @@CHANGE NOTICE:- This file was changed on July 22nd, 2020.+ This file was changed on July 22nd, 2020+ This file was changed on Jan 22, 2020+ - Added a method to wrap calls to d_print_comp() in order to track too much recursion*//* This code implements a demangler for the g++ V3 ABI. The ABI is@@ -309,6 +311,11 @@ struct d_print_infoint pack_index;/* Number of d_print_flush calls so far. */unsigned long int flush_count;++ // Changed Jan 22, 2020 - Added a method to wrap calls to d_print_comp() in+ // order to track too much recursion+ int recursion_level;+};#ifdef CP_DEMANGLE_DEBUG@@ -467,6 +474,12 @@ static inline char d_last_char (struct d_print_info *);static voidd_print_comp (struct d_print_info *, int, const struct demangle_component *);+// Changed Jan 22, 2020 - Added a method to wrap calls to d_print_comp() in+// order to track too much recursion+static void+d_print_comp_delegate (struct d_print_info *, int, const struct demangle_component *);++static voidd_print_java_identifier (struct d_print_info *, const char *, int);@@ -3667,6 +3680,7 @@ static voidd_print_init (struct d_print_info *dpi, demangle_callbackref callback,void *opaque){+dpi->len = 0;dpi->last_char = '\0';dpi->templates = NULL;@@ -3678,6 +3692,10 @@ d_print_init (struct d_print_info *dpi, demangle_callbackref callback,dpi->opaque = opaque;dpi->demangle_failure = 0;++ // Changed Jan 22, 2020 - Added a method to wrap calls to d_print_comp() in+ // order to track too much recursion+ dpi->recursion_level = 0;}/* Indicate that an error occurred during printing, and test for error. */@@ -3928,10 +3946,28 @@ d_print_subexpr (struct d_print_info *dpi, int options,/* Subroutine to handle components. */+ // Changed Jan 22, 2020 - Added a method to wrap calls to d_print_comp() in+ // order to track too much recursionstatic voidd_print_comp (struct d_print_info *dpi, int options,const struct demangle_component *dc){++ if (dpi->recursion_level > DEMANGLE_RECURSION_LIMIT) {+ d_print_error (dpi);+ return;+ }++ dpi->recursion_level++;+ d_print_comp_delegate(dpi, options, dc);+ dpi->recursion_level--;++}++static void+d_print_comp_delegate (struct d_print_info *dpi, int options,+ const struct demangle_component *dc)+{/* Magic variable to let reference smashing skip over the next modifierwithout needing to modify *dc. */const struct demangle_component *mod_inner = NULL;diff --git a/GPL/DemanglerGnu/src/demangler_gnu_v2_24/headers/demangle.h b/GPL/DemanglerGnu/src/demangler_gnu_v2_24/headers/demangle.hindex 1f6e9ea880..8b04be5ce1 100644--- a/GPL/DemanglerGnu/src/demangler_gnu_v2_24/headers/demangle.h+++ b/GPL/DemanglerGnu/src/demangler_gnu_v2_24/headers/demangle.h@@ -1,6 +1,5 @@/* ###* IP: LGPL 3.0- * REVIEWED: YES*//* Defs for interface to demanglers.Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002,@@ -71,6 +70,9 @@ extern "C" {/* If none of these are set, use 'current_demangling_style' as the default. */#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)+// Changed Jan 22, 2020 - Added constant to allow us to limit degenerate recursive calls+#define DEMANGLE_RECURSION_LIMIT 10000+/* Enumeration of possible demangling styles.Lucid and ARM styles are still kept logically distinct, even though