objdump: report no section contents

Message ID ZAnOVl9L363M77Cx@squeak.grove.modra.org
State Repeat Merge
Headers
Series objdump: report no section contents |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Alan Modra March 9, 2023, 12:17 p.m. UTC
  objdump's read_section is never used for bss-style sections, so to
plug a hole that fuzzers have found, exclude sections without
SEC_HAS_CONTENTS.

	* objdump.c (read_section): Report and return an error on
	a no contents section.
  

Patch

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 97532bed97c..0e8e1980b80 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4477,16 +4477,16 @@  read_section (bfd *abfd, const char *sect_name, bfd_byte **contents)
       return NULL;
     }
 
-  if (!bfd_malloc_and_get_section (abfd, sec, contents))
-    {
-      non_fatal (_("reading %s section of %s failed: %s"),
-		 sect_name, bfd_get_filename (abfd),
-		 bfd_errmsg (bfd_get_error ()));
-      exit_status = 1;
-      return NULL;
-    }
-
-  return sec;
+  if ((bfd_section_flags (sec) & SEC_HAS_CONTENTS) == 0)
+    bfd_set_error (bfd_error_no_contents);
+  else if (bfd_malloc_and_get_section (abfd, sec, contents))
+    return sec;
+
+  non_fatal (_("reading %s section of %s failed: %s"),
+	     sect_name, bfd_get_filename (abfd),
+	     bfd_errmsg (bfd_get_error ()));
+  exit_status = 1;
+  return NULL;
 }
 
 /* Stabs entries use a 12 byte format: