From patchwork Mon Oct 18 12:40:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 46340 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C73C3858027 for ; Mon, 18 Oct 2021 12:40:51 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 4A5213858400 for ; Mon, 18 Oct 2021 12:40:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A5213858400 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id F11BF3048E4D; Mon, 18 Oct 2021 14:40:42 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id A000E425A457; Mon, 18 Oct 2021 14:40:41 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: [COMMITTED] libdw: Don't pass NULL to dwarf_peel_type Date: Mon, 18 Oct 2021 14:40:35 +0200 Message-Id: <20211018124035.23055-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: Mark Wielaard Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" commit c3a6a9dfc "libdw: Use signedness of subrange type to determine array bounds" introduced a type check on a DIE which exposed a latent bug in the get_type function. Even if the type of a DIE couldn't be determined it would call dwarf_peel_type on it. The gcc undefined sanitizer would flag this as being undefined behaviour because the second argument of the function is marked as non-NULL. Fix this by checking we actually have a non-NULL type DIE. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 5 +++++ libdw/dwarf_aggregate_size.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 4275b830..311f34b5 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2021-10-18 Mark Wielaard + + * dwarf_aggregate_size.c (get_type): Don't pass NULL to + dwarf_peel_type. + 2021-10-06 Mark Wielaard * dwarf_aggregate_size.c (array_size): Check signedness of child DIE diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c index 96023d69..89f2029e 100644 --- a/libdw/dwarf_aggregate_size.c +++ b/libdw/dwarf_aggregate_size.c @@ -40,7 +40,7 @@ get_type (Dwarf_Die *die, Dwarf_Attribute *attr_mem, Dwarf_Die *type_mem) Dwarf_Die *type = INTUSE(dwarf_formref_die) (INTUSE(dwarf_attr_integrate) (die, DW_AT_type, attr_mem), type_mem); - if (INTUSE(dwarf_peel_type) (type, type) != 0) + if (type == NULL || INTUSE(dwarf_peel_type) (type, type) != 0) return NULL; return type;