public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdw: dwarf_peel_type break long chains/cycles.
@ 2018-06-18  8:42 Mark Wielaard
  2018-06-20 11:51 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2018-06-18  8:42 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Limit the number of chained modifiers to 64 (that is 8 chains for all
8 modifiers, most of which cannot be chained). This prevents loops in
the DWARF DIE DW_AT_type references.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdw/ChangeLog         |  4 ++++
 libdw/dwarf_peel_type.c | 23 ++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 5dc70ba9..754a7e15 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2018-06-18  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf_peel_type.c (dwarf_peel_type): Limit modifier chain to 64.
+
 2018-06-18  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf_aggregate_size.c (aggregate_size): Check die is not NULL.
diff --git a/libdw/dwarf_peel_type.c b/libdw/dwarf_peel_type.c
index 6bbfd424..59fc6f15 100644
--- a/libdw/dwarf_peel_type.c
+++ b/libdw/dwarf_peel_type.c
@@ -46,14 +46,19 @@ dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result)
 
   *result = *die;
   tag = INTUSE (dwarf_tag) (result);
-  while (tag == DW_TAG_typedef
-	 || tag == DW_TAG_const_type
-	 || tag == DW_TAG_volatile_type
-	 || tag == DW_TAG_restrict_type
-	 || tag == DW_TAG_atomic_type
-	 || tag == DW_TAG_immutable_type
-	 || tag == DW_TAG_packed_type
-	 || tag == DW_TAG_shared_type)
+
+/* Stack 8 of all these modifiers, after that it gets silly.  */
+#define MAX_DEPTH (8 * 8)
+  int max_depth = MAX_DEPTH;
+  while ((tag == DW_TAG_typedef
+	  || tag == DW_TAG_const_type
+	  || tag == DW_TAG_volatile_type
+	  || tag == DW_TAG_restrict_type
+	  || tag == DW_TAG_atomic_type
+	  || tag == DW_TAG_immutable_type
+	  || tag == DW_TAG_packed_type
+	  || tag == DW_TAG_shared_type)
+	&& max_depth-- > 0)
     {
       Dwarf_Attribute attr_mem;
       Dwarf_Attribute *attr = INTUSE (dwarf_attr_integrate) (result, DW_AT_type,
@@ -67,7 +72,7 @@ dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result)
       tag = INTUSE (dwarf_tag) (result);
     }
 
-  if (tag == DW_TAG_invalid)
+  if (tag == DW_TAG_invalid || max_depth <= 0)
     return -1;
 
   return 0;
-- 
2.17.0

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

* Re: [PATCH] libdw: dwarf_peel_type break long chains/cycles.
  2018-06-18  8:42 [PATCH] libdw: dwarf_peel_type break long chains/cycles Mark Wielaard
@ 2018-06-20 11:51 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2018-06-20 11:51 UTC (permalink / raw)
  To: elfutils-devel

On Mon, 2018-06-18 at 10:42 +0200, Mark Wielaard wrote:
> Limit the number of chained modifiers to 64 (that is 8 chains for all
> 8 modifiers, most of which cannot be chained). This prevents loops in
> the DWARF DIE DW_AT_type references.

Pushed to master.

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

end of thread, other threads:[~2018-06-20 11:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-18  8:42 [PATCH] libdw: dwarf_peel_type break long chains/cycles Mark Wielaard
2018-06-20 11:51 ` 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).