public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR28401, invalid section name lookup
@ 2021-10-06  0:53 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2021-10-06  0:53 UTC (permalink / raw)
  To: binutils

The PR28401 testcase has a section named "", ie. an empty string.
This results in some silly behaviour in load_debug_section, and
dump_dwarf_section.  Fix that.  Note that this patch doesn't correct
the main complaint in PR28401, "failed to allocate", since malloc
failures on sections having huge bogus sizes are to be expected.  We
can't safely catch all such cases by comparing with file size, for
example, where sections contain compressed data.

	PR 28401
	* objdump.c (load_debug_section): Don't attempt to retrieve
	empty name sections.
	(dump_dwarf_section): Likewise.

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 27bfb420399..fdffb8d5263 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3711,6 +3711,7 @@ load_debug_section (enum dwarf_section_display_enum debug, void *file)
   struct dwarf_section *section = &debug_displays [debug].section;
   bfd *abfd = (bfd *) file;
   asection *sec;
+  const char *name;
 
   /* If it is already loaded, do nothing.  */
   if (section->start != NULL)
@@ -3719,24 +3720,24 @@ load_debug_section (enum dwarf_section_display_enum debug, void *file)
 	return true;
     }
   /* Locate the debug section.  */
-  sec = bfd_get_section_by_name (abfd, section->uncompressed_name);
-  if (sec != NULL)
-    section->name = section->uncompressed_name;
-  else
+  name = section->uncompressed_name;
+  sec = bfd_get_section_by_name (abfd, name);
+  if (sec == NULL)
     {
-      sec = bfd_get_section_by_name (abfd, section->compressed_name);
-      if (sec != NULL)
-        section->name = section->compressed_name;
-      else
-	{
-	  sec = bfd_get_section_by_name (abfd, section->xcoff_name);
-	  if (sec != NULL)
-	    section->name = section->xcoff_name;
-	}
+      name = section->compressed_name;
+      if (*name)
+	sec = bfd_get_section_by_name (abfd, name);
+    }
+  if (sec == NULL)
+    {
+      name = section->xcoff_name;
+      if (*name)
+	sec = bfd_get_section_by_name (abfd, name);
     }
   if (sec == NULL)
     return false;
 
+  section->name = name;
   return load_specific_debug_section (debug, sec, file);
 }
 
@@ -3809,6 +3810,9 @@ dump_dwarf_section (bfd *abfd, asection *section,
   const char *match;
   int i;
 
+  if (*name == 0)
+    return;
+
   if (startswith (name, ".gnu.linkonce.wi."))
     match = ".debug_info";
   else

-- 
Alan Modra
Australia Development Lab, IBM

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

only message in thread, other threads:[~2021-10-06  0:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06  0:53 PR28401, invalid section name lookup Alan Modra

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