From: Andrew Burgess <aburgess@redhat.com>
To: binutils@sourceware.org
Subject: Ping: Re: [PATCH] bfd: make _bfd_section_size_insane part of the public API
Date: Tue, 02 Jan 2024 11:21:43 +0000 [thread overview]
Message-ID: <87cyuk9e0o.fsf@redhat.com> (raw)
In-Reply-To: <b9ff0c22bf79023edc29f8f661b683542b771cb2.1701879297.git.aburgess@redhat.com>
Ping!
Thanks,
Andrew
Andrew Burgess <aburgess@redhat.com> writes:
> 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(-)
>
> 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)
>
> base-commit: 5a22e042e41db962cd6a79cd59cab46cbbe58a98
> --
> 2.25.4
next prev parent reply other threads:[~2024-01-02 11:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-06 16:15 Andrew Burgess
2024-01-02 11:21 ` Andrew Burgess [this message]
2024-01-05 12:03 ` Jan Beulich
2024-01-10 11:03 ` Andrew Burgess
2024-01-10 12:47 ` Jan Beulich
2024-01-10 13:48 ` Andrew Burgess
2024-01-10 14:26 ` Jan Beulich
2024-01-10 16:20 ` Andrew Burgess
2024-01-10 21:22 ` Alan Modra
2024-01-11 8:23 ` Jan Beulich
2024-03-06 11:17 ` Andrew Burgess
2024-03-06 11:30 ` Jan Beulich
2024-03-25 18:33 ` Andrew Burgess
2024-01-10 17:54 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87cyuk9e0o.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).