From patchwork Fri Dec 17 22:52:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 49077 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 976F3385802A for ; Fri, 17 Dec 2021 22:52:52 +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 16DEA3858407 for ; Fri, 17 Dec 2021 22:52:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16DEA3858407 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 reform (deer0x12.wildebeest.org [172.31.17.148]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 683AF302FBA5; Fri, 17 Dec 2021 23:52:45 +0100 (CET) Received: by reform (Postfix, from userid 1000) id F0BAE2E8374A; Fri, 17 Dec 2021 23:52:44 +0100 (CET) From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: [PATCH] libdwfl: Make sure there is at least one phdr Date: Fri, 17 Dec 2021 23:52:42 +0100 Message-Id: <20211217225242.790500-1-mark@klomp.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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" The buffer read in needs to contain room for at least one Phdr. Signed-off-by: Mark Wielaard --- libdwfl/ChangeLog | 4 ++++ libdwfl/link_map.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index d4eee639..8760b1ef 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2021-12-16 Mark Wielaard + + * link_map.c (dwfl_link_map_report): Make sure phnum is non-zero. + 2021-12-16 Mark Wielaard * link_map.c (dwfl_link_map_report): Make sure dyn_filesz / entsize is diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index 177ad9a5..c4f79f11 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -890,6 +890,11 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, { nbytes = in.d_size; phnum = nbytes / phent; + if (phnum == 0) + { + __libdwfl_seterrno (DWFL_E_BADELF); + return false; + } } void *buf = malloc (nbytes); Elf32_Phdr (*p32)[phnum] = buf;