From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12169 invoked by alias); 7 Jun 2018 21:45:03 -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 12113 invoked by uid 89); 7 Jun 2018 21:45:02 -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= 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; Thu, 07 Jun 2018 21:45:00 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id AD6BB301470B; Thu, 7 Jun 2018 23:44:58 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id A72844337325; Thu, 7 Jun 2018 23:44:58 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH 1/2] libdw: Make sure that address_size and offset_size are 4 or 8 bytes. Date: Thu, 07 Jun 2018 21:45:00 -0000 Message-Id: <1528407882-16903-2-git-send-email-mark@klomp.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1528407882-16903-1-git-send-email-mark@klomp.org> References: <20180606203750.GC31910@wildebeest.org> <1528407882-16903-1-git-send-email-mark@klomp.org> X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q2/txt/msg00169.txt.bz2 When interning a CU make sure that address_size and offset_size are either 4 or 8 bytes. We really don't (want to) handle any other size. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 6 ++++++ libdw/libdw_findcu.c | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index b569393..9d0b484 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,9 @@ +2018-06-07 Mark Wielaard + + * libdw_findcu.c (__libdw_intern_next_unit): Report DWARF_E_VERSION, + not DWARF_E_INVALID_DWARF on unknown version. Set address_size and + offset_size to 8 when unknown. + 2018-06-06 Mark Wielaard * libdwP.h (__libdw_dieabbrev): Check DIE addr falls in cu. diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c index 2f5c6c4..ed74423 100644 --- a/libdw/libdw_findcu.c +++ b/libdw/libdw_findcu.c @@ -120,14 +120,23 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types) return NULL; /* We only know how to handle the DWARF version 2 through 5 formats. - For v4 debug types we only handle version 4. */ + For v4 debug types we only handle version 4. */ if (unlikely (version < 2) || unlikely (version > 5) || (debug_types && unlikely (version != 4))) { - __libdw_seterrno (DWARF_E_INVALID_DWARF); + __libdw_seterrno (DWARF_E_VERSION); return NULL; } + /* We only handle 32 or 64 bit (4 or 8 byte) addresses and offsets. + Just assume we are dealing with 64bit in case the size is "unknown". + Too much code assumes if it isn't 4 then it is 8 (or the other way + around). */ + if (unlikely (address_size != 4 && address_size != 8)) + address_size = 8; + if (unlikely (offset_size != 4 && offset_size != 8)) + offset_size = 8; + /* Invalid or truncated debug section data? */ size_t sec_idx = debug_types ? IDX_debug_types : IDX_debug_info; Elf_Data *data = dbg->sectiondata[sec_idx]; -- 1.8.3.1