]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: make _bfd_section_size_insane part of the public API
authorAndrew Burgess <aburgess@redhat.com>
Wed, 6 Dec 2023 13:27:20 +0000 (13:27 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 25 Mar 2024 18:31:38 +0000 (18:31 +0000)
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 (bfd_section_size_insane): Add declaration.
* compress.c (bfd_get_full_section_contents): Update for new name
of _bfd_section_size_insane.
(bfd_init_section_compress_status): Likewise.
* dwarf2.c (read_section): Likewise.
(_bfd_dwarf2_slurp_debug_info): Likewise.
* libbfd.h (_bfd_section_size_insane): Remove declaration.
* section.c (_bfd_section_size_insane): Rename to ...
(bfd_section_size_insane): ... this.

binutils/

* readelf.c (uncompress_section_contents): Update comment to
account for new name of _bfd_section_size_insane.

bfd/bfd-in2.h
bfd/compress.c
bfd/dwarf2.c
bfd/libbfd.h
bfd/section.c
binutils/readelf.c

index fa28688837c780474f75a52a917f0865762174a7..1166ddd75ef86aa76870e32a5d3a21f024566ba1 100644 (file)
@@ -1089,6 +1089,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
 {
index 38eb18233999f53ca6c568531a2a45e2e8ef5b18..19436a9395548d1cd2012a0e0ed02818d4eaa4f2 100644 (file)
@@ -739,7 +739,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.  */
@@ -1070,7 +1070,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;
index 5eda14e1e7ef397165977ae3c6909a855305709b..2e87d18a129e3337fe0705f66b0897b73a9b051c 100644 (file)
@@ -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"),
@@ -5520,7 +5520,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)
index f15b5f27db8cdbbf2ac7ba4aee2eef90b11fadca..7de23a50d189f573034846a40bd060821953a903 100644 (file)
@@ -3674,8 +3674,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 **,
index 8cd30e80f2b99c7e1cfaac06aa3af0ae5ae8f414..4eaa460a2a2542d5c219d71ce62e00909ac65d54 100644 (file)
@@ -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)
index 26e152fed935d57ba79a2c55688d2822a755c5ff..c1006480b7bc3e83dd87fb20d215342375614af9 100644 (file)
@@ -15902,7 +15902,7 @@ uncompress_section_contents (bool              is_zstd,
   z_stream strm;
   int rc;
 
-  /* Similar to _bfd_section_size_insane() in the BFD library we expect an
+  /* Similar to bfd_section_size_insane() in the BFD library we expect an
      upper limit of ~10x compression.  Any compression larger than that is
      thought to be due to fuzzing of the compression header.  */
   if (uncompressed_size > file_size * 10)