From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10155 invoked by alias); 10 Jun 2018 15:01:35 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 10142 invoked by uid 89); 10 Jun 2018 15:01:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Break, Stop, DIE X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Jun 2018 15:01:33 +0000 Received: from librem.wildebeest.org (deer0x15.wildebeest.org [172.31.17.151]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id CB3C83000ADD; Sun, 10 Jun 2018 17:01:30 +0200 (CEST) Received: by librem.wildebeest.org (Postfix, from userid 1000) id 1DF86141A87; Sun, 10 Jun 2018 17:01:30 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] libdw: Break long or circular DIE ref chains in dwarf_[has]attr_integrate. Date: Sun, 10 Jun 2018 15:01:00 -0000 Message-Id: <20180610150127.31036-1-mark@klomp.org> X-Mailer: git-send-email 2.17.0 X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q2/txt/msg00195.txt.bz2 Bad DWARF could create a very long or circular DIE ref chain by linking DW_AT_abstract_origin or DW_AT_specification to the DIE itself. Break the chain after seeing a large number (16) of DIEs. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 6 ++++++ libdw/dwarf_attr_integrate.c | 4 ++-- libdw/dwarf_hasattr_integrate.c | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 1195cf6e..07a1346b 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,9 @@ +2018-06-10 Mark Wielaard + + * dwarf_attr_integrate.c (dwarf_attr_integrate): Stop after 16 DIE + ref chains. + * dwarf_hasattr_integrate.c (dwarf_hasattr_integrate): Likewise. + 2018-06-08 Mark Wielaard * dwarf_getabbrev.c (dwarf_getabbrev): Check die and offset. diff --git a/libdw/dwarf_attr_integrate.c b/libdw/dwarf_attr_integrate.c index 748d988d..fc068638 100644 --- a/libdw/dwarf_attr_integrate.c +++ b/libdw/dwarf_attr_integrate.c @@ -38,7 +38,7 @@ dwarf_attr_integrate (Dwarf_Die *die, unsigned int search_name, Dwarf_Attribute *result) { Dwarf_Die die_mem; - + int chain = 16; /* Largest DIE ref chain we will follow. */ do { Dwarf_Attribute *attr = INTUSE(dwarf_attr) (die, search_name, result); @@ -53,7 +53,7 @@ dwarf_attr_integrate (Dwarf_Die *die, unsigned int search_name, die = INTUSE(dwarf_formref_die) (attr, &die_mem); } - while (die != NULL); + while (die != NULL && chain-- != 0); /* Not NULL if it didn't have abstract_origin and specification attributes. If it is a split CU then see if the skeleton diff --git a/libdw/dwarf_hasattr_integrate.c b/libdw/dwarf_hasattr_integrate.c index 4d4b4c54..1d946280 100644 --- a/libdw/dwarf_hasattr_integrate.c +++ b/libdw/dwarf_hasattr_integrate.c @@ -37,7 +37,7 @@ int dwarf_hasattr_integrate (Dwarf_Die *die, unsigned int search_name) { Dwarf_Die die_mem; - + int chain = 16; /* Largest DIE ref chain we will follow. */ do { if (INTUSE(dwarf_hasattr) (die, search_name)) @@ -53,7 +53,7 @@ dwarf_hasattr_integrate (Dwarf_Die *die, unsigned int search_name) die = INTUSE(dwarf_formref_die) (attr, &die_mem); } - while (die != NULL); + while (die != NULL && chain-- != 0); /* Not NULL if it didn't have abstract_origin and specification attributes. If it is a split CU then see if the skeleton -- 2.17.0