From patchwork Wed Aug 21 15:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 96244 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 8B0FC386F810 for ; Wed, 21 Aug 2024 15:11:47 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 34904385B50C for ; Wed, 21 Aug 2024 15:11:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34904385B50C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 34904385B50C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724253086; cv=none; b=oCu71ozXof2yJ+GJSqGZrk+um8KwaMhM1vIPvJzQA8LuTLIYsvW7bcjfh8B8xjKNxxktrNvrS6YhYtV0jJFbB1dhU0Twq4HS0/FPdzxOOXxupa1PHEH5YPxz+Y4y2fr3wUkF66hYOmSR+Ho8cEV4fjqcnxtlu75P6NcC3LaQtQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724253086; c=relaxed/simple; bh=jBzIoF7LLstBZ3qt0SdONSpc9ziMtdu3ul+jhd7aS8M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eG1SZFHA6nbypbg7MjVuLwRWsLXYaShOFsCM18hQseluUsPGWHUha/UhWzhkMmNV0OWOPWFSFrFLRBPYb5IxRuKLE8Y1ylV+Rn79ieokC5UMxaNdWfZD4vci7kXa2pBv7QufY7D0f+bCKrkYYrqwmjEsg+HjZnS9dvvhmNztidE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-39b32f258c8so3306085ab.1 for ; Wed, 21 Aug 2024 08:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1724253083; x=1724857883; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eMvzNbsScN0lqzaMUwZQqII6ljM7Z8d8+rDFte/+QTo=; b=U2Cdw6vIc51CJe69LkElE48vWxp74Zv+05gOMpzMshoY45BtMJa9JX8WhksbjZ9W0A 5Pg33L0wDOvJzEXsM64QPDTzALOewlzNfZCrG6cFvFd6NWou73q/5qkbJzEKGsIHPn1N CBtPnyohvgv/QfqZaQ9yPJF3dRGkPX7jc4Ej2C+GxaIr06Bs29pfj93HbYmCoxz19738 7BvgNLrxdf4VSS2y7QQTYrQkHlM2ChhjYRV2oXNhKaWupZrC1NN5EpSXrtIlLwS5hfUw oFfdxbCSLmB/jixcEjOFmSymFNeKh1sqkInGTrQXpikBgvThGsOINx5oKA9vAfpnn/AX 7QYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724253083; x=1724857883; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eMvzNbsScN0lqzaMUwZQqII6ljM7Z8d8+rDFte/+QTo=; b=oSy5cp64mrU8Pdvv6fk2V8sFTACPIBhkdTNe6K9CxrTmMXdNmoHT7loRjN98Oa1G0K VaqumzRY5DxGmUlx95MiBaUQJsFNHgnIYnFj+kzBRYru+RWIFrtguKwPcmeqNeTnlBoT bKfgDSIIJuFH040Yix8m0VDG6GWyTR7Rp2bboNbSxCWQL6yCFKU5VPTReFvcZVcQlH8L qG50hVsmukr10aDq9/+UAaYQ22luJ913P9Ex3EE0eY3Us4Oa+FWEOyba/A98V5U5CPGN YanDqSfzSpqVo41h/YGvOPh9DgWkDKior86kOViLb6CvAzH8oTFRLonRQXOVbZTUvbrJ tqwA== X-Gm-Message-State: AOJu0Yw4TUobdRmYOCu/Nv7AWKvUzZxCzKTWRQZhOPRxh0q5jUh13+8k c6ArUXAud5tir/th8Ox4FD09hY+R8HZS+srKH92Q0dbdOkVo/ME7yXi7Ea+nLYIGBGyFeA6ht6W gxA== X-Google-Smtp-Source: AGHT+IGdC8pt/5lXv1T32eUZ+Uo0z0BfeNJa9oYn6N4Q2gBzbEqDharzOQ+h6Q9usA5RUakbMZLP0g== X-Received: by 2002:a05:6e02:218d:b0:39d:24af:b004 with SMTP id e9e14a558f8ab-39d6c397e9bmr22393195ab.8.1724253083344; Wed, 21 Aug 2024 08:11:23 -0700 (PDT) Received: from localhost.localdomain (97-118-41-209.hlrn.qwest.net. [97.118.41.209]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-39d34be7fdesm34912635ab.72.2024.08.21.08.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 08:11:23 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Do not assume ELF in dwarf2/read.c Date: Wed, 21 Aug 2024 09:11:16 -0600 Message-ID: <20240821151116.3656049-1-tromey@adacore.com> X-Mailer: git-send-email 2.45.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org dwarf2/read.c has this code: else if (elf_section_data (sectp)->this_hdr.sh_size > bfd_get_file_size (abfd)) This assumes that the BFD is an ELF, which is an invalid assumption. A user noticed that this can sometimes cause a crash. This patch fixes the problem by changing this code to use bfd_section_size_insane. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32104 Reviewed-By: Tom de Vries Reviewed-by: Keith Seitz --- gdb/dwarf2/read.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index fde8eee6276..0f9874a9ce8 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1423,12 +1423,11 @@ dwarf2_per_bfd::locate_sections (bfd *abfd, asection *sectp, if ((aflag & SEC_HAS_CONTENTS) == 0) { } - else if (elf_section_data (sectp)->this_hdr.sh_size - > bfd_get_file_size (abfd)) + else if (bfd_section_size_insane (abfd, sectp)) { - bfd_size_type size = elf_section_data (sectp)->this_hdr.sh_size; - warning (_("Discarding section %s which has a section size (%s" - ") larger than the file size [in module %s]"), + bfd_size_type size = sectp->size; + warning (_("Discarding section %s which has an invalid size (%s" + ") [in module %s]"), bfd_section_name (sectp), phex_nz (size, sizeof (size)), bfd_get_filename (abfd)); }