public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC PATCH libiberty] Fix infinite recursion in demangler
@ 2017-03-08 13:22 Nathan Sidwell
  2017-03-08 13:29 ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Sidwell @ 2017-03-08 13:22 UTC (permalink / raw)
  To: GCC Patches, mjw

https://gcc.gnu.org/ml/gcc-patches/2017-03/msg00089.html?

Patch looks good to me (not a libiberty maintainer)

One question:
+  if (dc == NULL || dc->d_printing > 1)

Can dc ever be null here, or is this just extra defensiveness?

nathan

-- 
Nathan Sidwell

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH libiberty] Fix infinite recursion in demangler
  2017-03-08 13:22 [RFC PATCH libiberty] Fix infinite recursion in demangler Nathan Sidwell
@ 2017-03-08 13:29 ` Mark Wielaard
  2017-03-08 14:05   ` Nathan Sidwell
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Wielaard @ 2017-03-08 13:29 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: GCC Patches

On Wed, 2017-03-08 at 08:22 -0500, Nathan Sidwell wrote:
> https://gcc.gnu.org/ml/gcc-patches/2017-03/msg00089.html?
> 
> Patch looks good to me (not a libiberty maintainer)
> 
> One question:
> +  if (dc == NULL || dc->d_printing > 1)
> 
> Can dc ever be null here, or is this just extra defensiveness?

Yes, dc can be NULL. There is a similar check (and setting of
d_print_error) in d_print_comp_inner. 

Cheers,

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH libiberty] Fix infinite recursion in demangler
  2017-03-08 13:29 ` Mark Wielaard
@ 2017-03-08 14:05   ` Nathan Sidwell
  2017-03-12 13:55     ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Sidwell @ 2017-03-08 14:05 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: GCC Patches

On 03/08/2017 08:29 AM, Mark Wielaard wrote:
> On Wed, 2017-03-08 at 08:22 -0500, Nathan Sidwell wrote:
>> https://gcc.gnu.org/ml/gcc-patches/2017-03/msg00089.html?
>>
>> Patch looks good to me (not a libiberty maintainer)
>>
>> One question:
>> +  if (dc == NULL || dc->d_printing > 1)
>>
>> Can dc ever be null here, or is this just extra defensiveness?
>
> Yes, dc can be NULL. There is a similar check (and setting of
> d_print_error) in d_print_comp_inner.

thanks.  in case you'd not noticed Ian T's okayed my review.  so this is 
good to go

nathan

-- 
Nathan Sidwell

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH libiberty] Fix infinite recursion in demangler
  2017-03-08 14:05   ` Nathan Sidwell
@ 2017-03-12 13:55     ` Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2017-03-12 13:55 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: GCC Patches

On Wed, 2017-03-08 at 09:05 -0500, Nathan Sidwell wrote:
> thanks.  in case you'd not noticed Ian T's okayed my review.  so this is 
> good to go

Thanks. Markus pushed it including the testcases.

But there are still two testcase (not added, but attached below) that
are still failing (but now just don't demangle, not crash, so that is
progress). You might want to take a look at those since they seem
related to lambda functions: https://gcc.gnu.org/PR68700 and
https://gcc.gnu.org/PR70517
For both of these you can get a demangled symbol if you change the
recursion guard to be dc->d_printing > 2 (instead of 1). We aren't sure
these are valid mangled symbols though. They might represent bugs in the
mangler, not demangler.

Also Markus used Pedro's mangler/demangler dogfooding patch to generate
a list of mangled symbols gcc produces that the demangler cannot
demangle. None of these crash, but they do indicate a bug in either the
mangler or demangler code.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79976

Cheers,

Mark

#
# Test for allowing recursion when is_lambda_arg PR68700
_ZN8futurizeI13frozen_schemaE5applyIRZN7seastar7shardedIN7service13storage_proxyEE9invoke_onIZZNS6_22init_messaging_serviceEvENKUljN5utils4UUIDEE8_clEjSA_EUlOT_E_6futureIJS0_EEEET0_jSD_EUlvE_JEEESG_SD_DpOT0_
service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1} futurize<frozen_schema>::apply<future<frozen_schema> seastar::sharded<service::storage_proxy>::invoke_on<service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1}, future<frozen_schema> >(unsigned int, service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1})::{lambda()#1}&>(future<frozen_schema> seastar::sharded<service::storage_proxy>::invoke_on<service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1}, future<frozen_schema> >(unsigned int, service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1})::{lambda()#1}&)

#
# Test for allowing recursion when is_lambda_arg PR70517
_ZSt4moveIRZN11tconcurrent6futureIvE4thenIZ5awaitIS2_EDaOT_EUlRKS6_E_EENS1_INSt5decayIDTclfp_defpTEEE4typeEEES7_EUlvE_EONSt16remove_referenceIS6_E4typeES7_
std::remove_reference<tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}&>::type&& std::move<tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}&)::{lambda(auto:1&& const&)#1}>(tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}& const)::{lambda()#1}&>(tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}& const)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH libiberty] Fix infinite recursion in demangler
  2017-03-02  9:36 Markus Trippelsdorf
@ 2017-03-02 10:11 ` Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2017-03-02 10:11 UTC (permalink / raw)
  To: Markus Trippelsdorf; +Cc: gcc-patches

Hi,

On Thu, 2017-03-02 at 10:36 +0100, Markus Trippelsdorf wrote:
> The following patch from Mark Wielaard fixes many (all?) open demangler
> bugs that happen because we overflow the stack due to infinite
> recursion.
> 
> I'm not sure why Mark didn't post the patch himself.
> Anyway here it is.
> Any comments?

Thanks for poking at this issue. I didn't post it because I ran out of
time fully understanding why it works. I do believe this is the right
approach.  As far as I know the demangler can only be crashed by these
tricky endless recursion issues. All other crashers seem to have been
fixed already.

Below is some more explanation. More in the bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70909
I would certainly not mind if someone ran with this patch and made sure
it is fully correct. But there is one "magic bit" in there, that I
cannot fully explain.

> @@ -5683,9 +5684,16 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
>  
>  static void
>  d_print_comp (struct d_print_info *dpi, int options,
> -	      const struct demangle_component *dc)
> +	      struct demangle_component *dc)
>  {
>    struct d_component_stack self;
> +  if (dc == NULL || dc->d_printing > 1)
> +    {
> +      d_print_error (dpi);
> +      return;
> +    }
> +  else
> +    dc->d_printing++;
>  
>    self.dc = dc;
>    self.parent = dpi->component_stack;

The question is why must that be > 1, not >= 1 or some other constant?

In my local patch I added this comment:

+  /* We need to allow one level of recursion for function types,
+     which are printed recursively with different options depending
+     on whether or not the return type needs to be printed. And when
+     printing a lambda argument then we need to allow another level
+     of recursion to print it.  */

And to track that I introduced the following field in struct
d_print_info:

+  /* Whether a component has been pushed to the modifiers list to
+     print the function return type in the right place.  Used for
+     tracking allowed component recursion depth.  */
+  int func_ret_modifier;

Which is then initialized in d_print_init and incremented/decremented in
d_print_comp_inner around the recursive calls to d_print_comp to print
the return type.

To track the printing of lambda arguments the condition is then changed
to:

+  if (dc == NULL
+      || dc->d_printing > dpi->func_ret_modifier + dpi->is_lambda_arg)

I also added various testcases.

diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index b65dcd3..5fc1b9a 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -4666,3 +4666,44 @@ void eat<int*, Foo()::{lambda(auto:1*, auto:2*)#6}>(int*&, Foo()::{lambda(auto:1
 
 _Z3eatIPiZ3BarIsEvvEUlPsPT_PT0_E0_EvRS3_RS5_
 void eat<int*, void Bar<short>()::{lambda(short*, auto:1*, auto:2*)#2}>(int*&, void Bar<short>()::{lambda(short*, auto:1*, auto:2*)#2}&)
+#
+# Test recursion PR67264
+
+_Z1KIStcvT_E
+_Z1KIStcvT_E
+
+_ZcvT_IIS0_EE
+_ZcvT_IIS0_EE
+
+_ZcvT_IZcvT_E1fE
+_ZcvT_IZcvT_E1fE
+
+_Z1gINcvT_EE
+_Z1gINcvT_EE
+
+_ZcvT_ILZcvDTT_EEE
+_ZcvT_ILZcvDTT_EEE
+
+_Z1gIJOOT_EEOT_c
+_Z1gIJOOT_EEOT_c
+
+_Z1KMMMMMMMMMMMMMMMA_xooooooooooooooo
+_Z1KMMMMMMMMMMMMMMMA_xooooooooooooooo
+
+_ZdvMMMMMMMMMMMMMrrrrA_DTdvfp_fp_Eededilfdfdfdfd
+_ZdvMMMMMMMMMMMMMrrrrA_DTdvfp_fp_Eededilfdfdfdfd
+#
+# Test for Infinite Recursion PR70909
+
+_Z1MA_aMMMMA_MMA_MMMMMMMMSt1MS_o11T0000000000t2M0oooozoooo
+_Z1MA_aMMMMA_MMA_MMMMMMMMSt1MS_o11T0000000000t2M0oooozoooo
+
+#
+# Test for allowing recursion when is_lambda_arg PR68700
+_ZN8futurizeI13frozen_schemaE5applyIRZN7seastar7shardedIN7service13storage_proxyEE9invoke_onIZZNS6_22init_messaging_serviceEvENKUljN5utils4UUIDEE8_clEjSA_EUlOT_E_6futureIJS0_EEEET0_jSD_EUlvE_JEEESG_SD_DpOT0_
+service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1} futurize<frozen_schema>::apply<future<frozen_schema> seastar::sharded<service::storage_proxy>::invoke_on<service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1}, future<frozen_schema> >(unsigned int, service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1})::{lambda()#1}&>(future<frozen_schema> seastar::sharded<service::storage_proxy>::invoke_on<service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1}, future<frozen_schema> >(unsigned int, service::storage_proxy::init_messaging_service()::{lambda(unsigned int, utils::UUID)#10}::operator()(unsigned int, utils::UUID) const::{lambda(auto:1&&)#1})::{lambda()#1}&)
+
+#
+# Test for allowing recursion when is_lambda_arg PR70517
+_ZSt4moveIRZN11tconcurrent6futureIvE4thenIZ5awaitIS2_EDaOT_EUlRKS6_E_EENS1_INSt5decayIDTclfp_defpTEEE4typeEEES7_EUlvE_EONSt16remove_referenceIS6_E4typeES7_
+std::remove_reference<tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}&>::type&& std::move<tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}&)::{lambda(auto:1&& const&)#1}>(tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}& const)::{lambda()#1}&>(tconcurrent::future<std::decay<decltype ({parm#1}(*this))>::type> tconcurrent::future<void>::then<auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}>(auto await<tconcurrent::future<void> >(tconcurrent::future<void>&&)::{lambda(auto:1&& const&)#1}&& const)::{lambda()#1}& const)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH libiberty] Fix infinite recursion in demangler
@ 2017-03-02  9:36 Markus Trippelsdorf
  2017-03-02 10:11 ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Trippelsdorf @ 2017-03-02  9:36 UTC (permalink / raw)
  To: gcc-patches; +Cc: Mark Wielaard

The following patch from Mark Wielaard fixes many (all?) open demangler
bugs that happen because we overflow the stack due to infinite
recursion.

I'm not sure why Mark didn't post the patch himself.
Anyway here it is.
Any comments?
Thanks.

diff --git a/include/demangle.h b/include/demangle.h
index 7cc955dc28d5..996203b2d786 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -494,6 +494,11 @@ struct demangle_component
   /* The type of this component.  */
   enum demangle_component_type type;
 
+  /* Guard against recursive component printing.
+     Initialize to zero.  Private to d_print_comp.
+     All other fields are final after initialization.  */
+  int d_printing;
+
   union
   {
     /* For DEMANGLE_COMPONENT_NAME.  */
@@ -688,7 +693,7 @@ cplus_demangle_v3_components (const char *mangled, int options, void **mem);
 
 extern char *
 cplus_demangle_print (int options,
-                      const struct demangle_component *tree,
+                      struct demangle_component *tree,
                       int estimated_length,
                       size_t *p_allocated_size);
 
@@ -708,7 +713,7 @@ cplus_demangle_print (int options,
 
 extern int
 cplus_demangle_print_callback (int options,
-                               const struct demangle_component *tree,
+                               struct demangle_component *tree,
                                demangle_callbackref callback, void *opaque);
 
 #ifdef __cplusplus
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index f0dbf9381c6b..341a4182c0b6 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -172,10 +172,10 @@ static struct demangle_component *d_mangled_name (struct d_info *, int);
 static struct demangle_component *d_type (struct d_info *);
 
 #define cplus_demangle_print d_print
-static char *d_print (int, const struct demangle_component *, int, size_t *);
+static char *d_print (int, struct demangle_component *, int, size_t *);
 
 #define cplus_demangle_print_callback d_print_callback
-static int d_print_callback (int, const struct demangle_component *,
+static int d_print_callback (int, struct demangle_component *,
                              demangle_callbackref, void *);
 
 #define cplus_demangle_init_info d_init_info
@@ -264,7 +264,7 @@ struct d_print_mod
      in which they appeared in the mangled string.  */
   struct d_print_mod *next;
   /* The modifier.  */
-  const struct demangle_component *mod;
+  struct demangle_component *mod;
   /* Whether this modifier was printed.  */
   int printed;
   /* The list of templates which applies to this modifier.  */
@@ -530,7 +530,7 @@ static inline void d_append_string (struct d_print_info *, const char *);
 static inline char d_last_char (struct d_print_info *);
 
 static void
-d_print_comp (struct d_print_info *, int, const struct demangle_component *);
+d_print_comp (struct d_print_info *, int, struct demangle_component *);
 
 static void
 d_print_java_identifier (struct d_print_info *, const char *, int);
@@ -539,25 +539,25 @@ static void
 d_print_mod_list (struct d_print_info *, int, struct d_print_mod *, int);
 
 static void
-d_print_mod (struct d_print_info *, int, const struct demangle_component *);
+d_print_mod (struct d_print_info *, int, struct demangle_component *);
 
 static void
 d_print_function_type (struct d_print_info *, int,
-                       const struct demangle_component *,
+                       struct demangle_component *,
                        struct d_print_mod *);
 
 static void
 d_print_array_type (struct d_print_info *, int,
-                    const struct demangle_component *,
+                    struct demangle_component *,
                     struct d_print_mod *);
 
 static void
-d_print_expr_op (struct d_print_info *, int, const struct demangle_component *);
+d_print_expr_op (struct d_print_info *, int, struct demangle_component *);
 
 static void d_print_cast (struct d_print_info *, int,
-			  const struct demangle_component *);
+			  struct demangle_component *);
 static void d_print_conversion (struct d_print_info *, int,
-				const struct demangle_component *);
+				struct demangle_component *);
 
 static int d_demangle_callback (const char *, int,
                                 demangle_callbackref, void *);
@@ -923,6 +923,7 @@ d_make_empty (struct d_info *di)
   if (di->next_comp >= di->num_comps)
     return NULL;
   p = &di->comps[di->next_comp];
+  p->d_printing = 0;
   ++di->next_comp;
   return p;
 }
@@ -4249,7 +4250,7 @@ d_last_char (struct d_print_info *dpi)
 CP_STATIC_IF_GLIBCPP_V3
 int
 cplus_demangle_print_callback (int options,
-                               const struct demangle_component *dc,
+                               struct demangle_component *dc,
                                demangle_callbackref callback, void *opaque)
 {
   struct d_print_info dpi;
@@ -4292,7 +4293,7 @@ cplus_demangle_print_callback (int options,
 
 CP_STATIC_IF_GLIBCPP_V3
 char *
-cplus_demangle_print (int options, const struct demangle_component *dc,
+cplus_demangle_print (int options, struct demangle_component *dc,
                       int estimate, size_t *palc)
 {
   struct d_growable_string dgs;
@@ -4452,7 +4453,7 @@ d_args_length (struct d_print_info *dpi, const struct demangle_component *dc)
 
 static void
 d_print_subexpr (struct d_print_info *dpi, int options,
-		 const struct demangle_component *dc)
+		 struct demangle_component *dc)
 {
   int simple = 0;
   if (dc->type == DEMANGLE_COMPONENT_NAME
@@ -4528,9 +4529,9 @@ d_get_saved_scope (struct d_print_info *dpi,
 
 static int
 d_maybe_print_fold_expression (struct d_print_info *dpi, int options,
-			       const struct demangle_component *dc)
+			       struct demangle_component *dc)
 {
-  const struct demangle_component *ops, *operator_, *op1, *op2;
+  struct demangle_component *ops, *operator_, *op1, *op2;
   int save_idx;
 
   const char *fold_code = d_left (dc)->u.s_operator.op->code;
@@ -4591,11 +4592,11 @@ d_maybe_print_fold_expression (struct d_print_info *dpi, int options,
 
 static void
 d_print_comp_inner (struct d_print_info *dpi, int options,
-		    const struct demangle_component *dc)
+		    struct demangle_component *dc)
 {
   /* Magic variable to let reference smashing skip over the next modifier
      without needing to modify *dc.  */
-  const struct demangle_component *mod_inner = NULL;
+  struct demangle_component *mod_inner = NULL;
 
   /* Variable used to store the current templates while a previously
      captured scope is used.  */
@@ -4980,7 +4981,7 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
     case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
       {
 	/* Handle reference smashing: & + && = &.  */
-	const struct demangle_component *sub = d_left (dc);
+	struct demangle_component *sub = d_left (dc);
 	if (!dpi->is_lambda_arg
 	    && sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
 	  {
@@ -5683,9 +5684,16 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
 
 static void
 d_print_comp (struct d_print_info *dpi, int options,
-	      const struct demangle_component *dc)
+	      struct demangle_component *dc)
 {
   struct d_component_stack self;
+  if (dc == NULL || dc->d_printing > 1)
+    {
+      d_print_error (dpi);
+      return;
+    }
+  else
+    dc->d_printing++;
 
   self.dc = dc;
   self.parent = dpi->component_stack;
@@ -5694,6 +5702,7 @@ d_print_comp (struct d_print_info *dpi, int options,
   d_print_comp_inner (dpi, options, dc);
 
   dpi->component_stack = self.parent;
+  dc->d_printing--;
 }
 
 /* Print a Java dentifier.  For Java we try to handle encoded extended
@@ -5835,7 +5844,7 @@ d_print_mod_list (struct d_print_info *dpi, int options,
 
 static void
 d_print_mod (struct d_print_info *dpi, int options,
-             const struct demangle_component *mod)
+             struct demangle_component *mod)
 {
   switch (mod->type)
     {
@@ -5927,7 +5936,7 @@ d_print_mod (struct d_print_info *dpi, int options,
 
 static void
 d_print_function_type (struct d_print_info *dpi, int options,
-                       const struct demangle_component *dc,
+                       struct demangle_component *dc,
                        struct d_print_mod *mods)
 {
   int need_paren;
@@ -6005,7 +6014,7 @@ d_print_function_type (struct d_print_info *dpi, int options,
 
 static void
 d_print_array_type (struct d_print_info *dpi, int options,
-                    const struct demangle_component *dc,
+                    struct demangle_component *dc,
                     struct d_print_mod *mods)
 {
   int need_space;
@@ -6059,7 +6068,7 @@ d_print_array_type (struct d_print_info *dpi, int options,
 
 static void
 d_print_expr_op (struct d_print_info *dpi, int options,
-                 const struct demangle_component *dc)
+                 struct demangle_component *dc)
 {
   if (dc->type == DEMANGLE_COMPONENT_OPERATOR)
     d_append_buffer (dpi, dc->u.s_operator.op->name,
@@ -6072,7 +6081,7 @@ d_print_expr_op (struct d_print_info *dpi, int options,
 
 static void
 d_print_cast (struct d_print_info *dpi, int options,
-		    const struct demangle_component *dc)
+	      struct demangle_component *dc)
 {
   d_print_comp (dpi, options, d_left (dc));
 }
@@ -6081,7 +6090,7 @@ d_print_cast (struct d_print_info *dpi, int options,
 
 static void
 d_print_conversion (struct d_print_info *dpi, int options,
-		    const struct demangle_component *dc)
+		    struct demangle_component *dc)
 {
   struct d_print_template dpt;
 
diff --git a/libiberty/cp-demint.c b/libiberty/cp-demint.c
index 64baffac8ddc..13a71d96dec1 100644
--- a/libiberty/cp-demint.c
+++ b/libiberty/cp-demint.c
@@ -123,6 +123,7 @@ cplus_demangle_fill_component (struct demangle_component *p,
   p->type = type;
   p->u.s_binary.left = left;
   p->u.s_binary.right = right;
+  p->d_printing = 0;
 
   return 1;
 }
@@ -146,6 +147,7 @@ cplus_demangle_fill_builtin_type (struct demangle_component *p,
 	{
 	  p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
 	  p->u.s_builtin.type = &cplus_demangle_builtin_types[i];
+	  p->d_printing = 0;
 	  return 1;
 	}
     }
@@ -172,6 +174,7 @@ cplus_demangle_fill_operator (struct demangle_component *p,
 	{
 	  p->type = DEMANGLE_COMPONENT_OPERATOR;
 	  p->u.s_operator.op = &cplus_demangle_operators[i];
+	  p->d_printing = 0;
 	  return 1;
 	}
     }
-- 
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-12 13:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-08 13:22 [RFC PATCH libiberty] Fix infinite recursion in demangler Nathan Sidwell
2017-03-08 13:29 ` Mark Wielaard
2017-03-08 14:05   ` Nathan Sidwell
2017-03-12 13:55     ` Mark Wielaard
  -- strict thread matches above, loose matches on Subject: below --
2017-03-02  9:36 Markus Trippelsdorf
2017-03-02 10:11 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).