From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 790643857415 for ; Mon, 9 May 2022 16:49:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 790643857415 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 83EE33000599; Mon, 9 May 2022 18:49:00 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id F3EB640216A6; Mon, 9 May 2022 18:48:59 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] libdw: Add sanity check to store_implicit_value Date: Mon, 9 May 2022 18:48:58 +0200 Message-Id: <20220509164858.26359-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 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, T_SCC_BODY_TEXT_LINE 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: , X-List-Received-Date: Mon, 09 May 2022 16:49:04 -0000 Don't just skip the block length, but check it is equal to the op->number that we are going to use as length. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 4 ++++ libdw/dwarf_getlocation.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 631f2f2a..b254d9cd 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2022-05-09 Mark Wielaard + + * dwarf_getlocation.c (store_implicit_value): Check block length. + 2022-04-16 Mark Wielaard * libdwP.h: Remove atomics.h include. diff --git a/libdw/dwarf_getlocation.c b/libdw/dwarf_getlocation.c index 5db3cf97..d0d78163 100644 --- a/libdw/dwarf_getlocation.c +++ b/libdw/dwarf_getlocation.c @@ -147,7 +147,10 @@ store_implicit_value (Dwarf *dbg, void **cache, Dwarf_Op *op) sizeof (struct loc_block_s), 1); const unsigned char *data = (const unsigned char *) (uintptr_t) op->number2; /* Skip the block length. */ - __libdw_get_uleb128_unchecked (&data); + Dwarf_Word length; + get_uleb128_unchecked (length, data); + if (length != op->number) + return -1; block->addr = op; block->data = (unsigned char *) data; block->length = op->number; -- 2.18.4