From patchwork Wed Dec 6 16:15:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 81526 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 7B97C3858C3A for ; Wed, 6 Dec 2023 16:15:52 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 5924C3858D20 for ; Wed, 6 Dec 2023 16:15:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5924C3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5924C3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701879337; cv=none; b=tcmf093ifYVBQeniZC+tvb6olq+FOBjcyDY9jt6c4KmC0dMtHnKU0EqefkX8X6AIpFCSbx9Hp5dvrgLltEieNIXwE2efXe9RD3yarKeg+ew732VA0SNcWaDccH8W7DYd83l+HP7E3HLT0o1/ws3NfKe6aSIAJc9CO0nNcclkVwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701879337; c=relaxed/simple; bh=EiuNjmBev3PcfTnbaNAup1/5yFNVZ77wu2w6QiZTLUI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oFPB2cGg2MAVcAonkAlQ+6b+TcVPnGDMz5Z6q6T2NiXCft7DTjomoS43PSc8rZIbtsobgjHPJcOe01CVb7Xekb9j0N6KPzo0uZINjxXaLS5bCzFaBDtxkft7GMIYjl63NHd+kdMarqhj+GxRvCjb5WyKdhpNeBrcM2VJjzo6+rA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701879334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=O1vOQnE8Zv9hm44oIUMIt6k6iWE4uOhPjaWyMOz4s9c=; b=OphqTiNFKFB9ze1e68Icd7Rf9CX7WPzmRZGeH8Q6leuBaqdfNiR62zFAkyvOPi4c0zqdun yMVQEziMAhjQX6ooAUbycXAVCkHkI9DP1JgPqcEHSIn2ps/K2TlF9uJZXD3VORkyEFuk2e pITBrcTcQETDXmjg1uIr2sS4h+En+c4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-Fm-HdaJdPHilDlermj79CA-1; Wed, 06 Dec 2023 11:15:31 -0500 X-MC-Unique: Fm-HdaJdPHilDlermj79CA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40b3dbe99d9so53521365e9.1 for ; Wed, 06 Dec 2023 08:15:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701879329; x=1702484129; 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=O1vOQnE8Zv9hm44oIUMIt6k6iWE4uOhPjaWyMOz4s9c=; b=dKge2Zs1X5qwI7XsNMdikD5wqAEXSGissWhXz2S9C0YS7LP0OiQM2EyRwV4Oo0ZsFn eAGsryWZgGWku1+wiPpb31QFRlylmkKAkcrUdQ/FZBbn52JPMCS1reVXVCNpxtnJq4Ya YXMZR2RcOg/M6N+aGyfphHTOv4NhIKi0vDx9A2QFfY4v8WyqcGlo+L8i+FGmY2Scg7HK c6olnOZgh59Dsl/qC7ptgfsYxQkdH94vohGi9RXexihYS4i33kIQh8oH7hTGqihgS7JO 36ddCSZtlWjV8WYOg1eVNvBLXJR8Gac/D3PlUOKD5if7D1SuiWAHWM0fHUnfA+gVbfGa x0SQ== X-Gm-Message-State: AOJu0Yy+h9yajNi41rL58x/6n1LKSypLwjfs0wB+RQi6P4FEqK68xbA/ Ta7EOOS8920+WAAJWqS0vb9+106vWsCXejn+TQjmT5vUdaC4xZTW+Sycn35ZUmo8BfE+ILCZAj+ ViQMpWC9TwI5Dsb58id9oC4otmzpN5wlKPIoPs5HoPsr2ukYwGBAHSJJDfDG85E8uZjqbiDH9an taHg== X-Received: by 2002:a05:600c:5493:b0:40c:c99:1d6d with SMTP id iv19-20020a05600c549300b0040c0c991d6dmr613475wmb.104.1701879329288; Wed, 06 Dec 2023 08:15:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmjTxKFoPidg5lQDksGB2/VUwpXy3pzTJzEPDr/zed+zWUFDiysyYe+dJM0LyfG/M+/RY0hQ== X-Received: by 2002:a05:600c:5493:b0:40c:c99:1d6d with SMTP id iv19-20020a05600c549300b0040c0c991d6dmr613468wmb.104.1701879328905; Wed, 06 Dec 2023 08:15:28 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id w12-20020adfee4c000000b0033334c3acb6sm36054wro.98.2023.12.06.08.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:15:28 -0800 (PST) From: Andrew Burgess To: binutils@sourceware.org Cc: Andrew Burgess Subject: [PATCH] bfd: make _bfd_section_size_insane part of the public API Date: Wed, 6 Dec 2023 16:15:26 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org If a BFD user is making use of a function like bfd_get_section_contents to read a section into a pre-allocated buffer, then that BFD user might also want to make use of _bfd_section_size_insane prior to allocating the buffer they intend to use in order to validate that the buffer size that plan to allocate is sane. This commit makes _bfd_section_size_insane public, by renaming it to bfd_section_size_insane. I've updated the existing uses within bfd/, I don't believe this function is used outside of bfd/ currently. One place that I plan to make use of this function is in gdb/gdb_bfd.c, in the function gdb_bfd_get_full_section_contents. This change isn't included in this commit, but will come later if/when this has been merged into bfd. There should be no change in behaviour after this commit. --- bfd/bfd-in2.h | 2 ++ bfd/compress.c | 4 ++-- bfd/dwarf2.c | 4 ++-- bfd/libbfd.h | 2 -- bfd/section.c | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) base-commit: 5a22e042e41db962cd6a79cd59cab46cbbe58a98 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 040d5560cdf..c3ade639ad7 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1088,6 +1088,8 @@ const char *bfd_generic_group_name (bfd *, const asection *sec); bool bfd_generic_discard_group (bfd *abfd, asection *group); +bool bfd_section_size_insane (bfd *abfd, asection *sec); + /* Extracted from syms.c. */ typedef struct bfd_symbol { diff --git a/bfd/compress.c b/bfd/compress.c index 7ec7b0edf38..17f996f1613 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -735,7 +735,7 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr) if (p == NULL && compress_status != COMPRESS_SECTION_DONE - && _bfd_section_size_insane (abfd, sec)) + && bfd_section_size_insane (abfd, sec)) { /* PR 24708: Avoid attempts to allocate a ridiculous amount of memory. */ @@ -1066,7 +1066,7 @@ bfd_init_section_compress_status (bfd *abfd, sec_ptr sec) || sec->rawsize != 0 || sec->contents != NULL || sec->compress_status != COMPRESS_SECTION_NONE - || _bfd_section_size_insane (abfd, sec)) + || bfd_section_size_insane (abfd, sec)) { bfd_set_error (bfd_error_invalid_operation); return false; diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 22e6b467598..771929a8c28 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -716,7 +716,7 @@ read_section (bfd *abfd, return false; } - if (_bfd_section_size_insane (abfd, msec)) + if (bfd_section_size_insane (abfd, msec)) { /* PR 26946 */ _bfd_error_handler (_("DWARF error: section %s is too big"), @@ -5498,7 +5498,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd, msec; msec = find_debug_info (debug_bfd, debug_sections, msec)) { - if (_bfd_section_size_insane (debug_bfd, msec)) + if (bfd_section_size_insane (debug_bfd, msec)) goto restore_vma; /* Catch PR25070 testcase overflowing size calculation here. */ if (total_size + msec->size < total_size) diff --git a/bfd/libbfd.h b/bfd/libbfd.h index cc432677a81..c7ae249dfea 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -3641,8 +3641,6 @@ bool _bfd_unrecognized_reloc unsigned int r_type) ATTRIBUTE_HIDDEN; /* Extracted from section.c. */ -bool _bfd_section_size_insane (bfd *abfd, asection *sec) ATTRIBUTE_HIDDEN; - /* Extracted from stabs.c. */ bool _bfd_link_section_stabs (bfd *, struct stab_info *, asection *, asection *, void **, diff --git a/bfd/section.c b/bfd/section.c index e9af59dfd15..c9e5d3e0b65 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -1715,11 +1715,11 @@ _bfd_nowrite_set_section_contents (bfd *abfd, } /* -INTERNAL_FUNCTION - _bfd_section_size_insane +FUNCTION + bfd_section_size_insane SYNOPSIS - bool _bfd_section_size_insane (bfd *abfd, asection *sec); + bool bfd_section_size_insane (bfd *abfd, asection *sec); DESCRIPTION Returns true if the given section has a size that indicates @@ -1729,7 +1729,7 @@ DESCRIPTION */ bool -_bfd_section_size_insane (bfd *abfd, asection *sec) +bfd_section_size_insane (bfd *abfd, asection *sec) { bfd_size_type size = bfd_get_section_limit_octets (abfd, sec); if (size == 0)