public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] Fix an attempt to allocate an unreasonably large amount of memory when parsing a corrupt ELF file.
@ 2022-12-21 11:52 Nick Clifton
  0 siblings, 0 replies; only message in thread
From: Nick Clifton @ 2022-12-21 11:52 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=75393a2d54bcc40053e5262a3de9d70c5ebfbbfd

commit 75393a2d54bcc40053e5262a3de9d70c5ebfbbfd
Author: Nick Clifton <nickc@redhat.com>
Date:   Wed Dec 21 11:51:23 2022 +0000

    Fix an attempt to allocate an unreasonably large amount of memory when parsing a corrupt ELF file.
    
            PR  29924
            * objdump.c (load_specific_debug_section): Check for excessively
            large sections.

Diff:
---
 binutils/ChangeLog | 6 ++++++
 binutils/objdump.c | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index e7f918d3f65..020e09f3700 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2022-12-21  Nick Clifton  <nickc@redhat.com>
+
+	PR  29924
+	* objdump.c (load_specific_debug_section): Check for excessively
+	large sections.
+
 2022-12-19  Tom Tromey  <tromey@adacore.com>
 
 	* dwarf-mode.el (dwarf-do-refresh): Avoid compiler warning.
diff --git a/binutils/objdump.c b/binutils/objdump.c
index d51abbe3858..2eb02de0e76 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4225,7 +4225,9 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
   section->size = bfd_section_size (sec);
   /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
   alloced = amt = section->size + 1;
-  if (alloced != amt || alloced == 0)
+  if (alloced != amt
+      || alloced == 0
+      || (bfd_get_size (abfd) != 0 && alloced >= bfd_get_size (abfd)))
     {
       section->start = NULL;
       free_debug_section (debug);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-21 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 11:52 [binutils-gdb] Fix an attempt to allocate an unreasonably large amount of memory when parsing a corrupt ELF file Nick Clifton

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).