From patchwork Sun Dec 19 19:25:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 49098 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 7132A385842C for ; Sun, 19 Dec 2021 19:25:22 +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 4B7B13858400 for ; Sun, 19 Dec 2021 19:25:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4B7B13858400 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 EC1F2302FBA8; Sun, 19 Dec 2021 20:25:14 +0100 (CET) Received: by reform (Postfix, from userid 1000) id 982182E8374A; Sun, 19 Dec 2021 20:25:14 +0100 (CET) From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: [PATCH] libdwfl: Make sure that ph_buffer_size has room for at least one phdr Date: Sun, 19 Dec 2021 20:25:12 +0100 Message-Id: <20211219192512.925744-1-mark@klomp.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 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" dwfl_segment_report_module might otherwise try to handle half a phdr taking the other half from after the buffer. Signed-off-by: Mark Wielaard --- libdwfl/ChangeLog | 5 +++++ libdwfl/dwfl_segment_report_module.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index d00ce702..38e2bdaa 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2021-12-08 Mark Wielaard + + * dwfl_segment_report_module.c (dwfl_segment_report_module): Make sure + that ph_buffer_size has room for at least one phdr. + 2021-12-08 Mark Wielaard * dwfl_segment_report_module.c (dwfl_segment_report_module): Make diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index 89e05103..840d6f44 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -426,7 +426,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, buffer, otherwise it will be the size of the new buffer that could be read. */ if (ph_buffer_size != 0) - xlatefrom.d_size = ph_buffer_size; + { + phnum = ph_buffer_size / phentsize; + if (phnum == 0) + goto out; + xlatefrom.d_size = ph_buffer_size; + } xlatefrom.d_buf = ph_buffer;