PR29922, SHT_NOBITS section avoids section size sanity check
authorAlan Modra <amodra@gmail.com>
Tue, 20 Dec 2022 13:17:03 +0000 (23:47 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 21 Dec 2022 07:25:34 +0000 (17:55 +1030)
PR 29922
* dwarf2.c (find_debug_info): Ignore sections without
SEC_HAS_CONTENTS.

bfd/dwarf2.c

index 95f45708e9d155ce349653bdf24eeadc1ee92de5..0cd8152ee6e4f84d6adb272333d8bbb58b84c6e0 100644 (file)
@@ -4831,16 +4831,19 @@ find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections,
     {
       look = debug_sections[debug_info].uncompressed_name;
       msec = bfd_get_section_by_name (abfd, look);
-      if (msec != NULL)
+      /* Testing SEC_HAS_CONTENTS is an anti-fuzzer measure.  Of
+        course debug sections always have contents.  */
+      if (msec != NULL && (msec->flags & SEC_HAS_CONTENTS) != 0)
        return msec;
 
       look = debug_sections[debug_info].compressed_name;
       msec = bfd_get_section_by_name (abfd, look);
-      if (msec != NULL)
+      if (msec != NULL && (msec->flags & SEC_HAS_CONTENTS) != 0)
         return msec;
 
       for (msec = abfd->sections; msec != NULL; msec = msec->next)
-       if (startswith (msec->name, GNU_LINKONCE_INFO))
+       if ((msec->flags & SEC_HAS_CONTENTS) != 0
+           && startswith (msec->name, GNU_LINKONCE_INFO))
          return msec;
 
       return NULL;
@@ -4848,6 +4851,9 @@ find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections,
 
   for (msec = after_sec->next; msec != NULL; msec = msec->next)
     {
+      if ((msec->flags & SEC_HAS_CONTENTS) == 0)
+       continue;
+
       look = debug_sections[debug_info].uncompressed_name;
       if (strcmp (msec->name, look) == 0)
        return msec;