]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR 33473 SEGV in _bfd_elf_gc_mark_debug_special_section_group
authorAlan Modra <amodra@gmail.com>
Mon, 24 Nov 2025 08:16:35 +0000 (18:46 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 24 Nov 2025 21:20:17 +0000 (07:50 +1030)
The code that faulted made the assumption that a group section always
had at least one valid member.  Fix that assumption.  Also fail if all
entries in a SHT_GROUP section are invalid.  (An empty group will not
result in a call to process_sht_group_entries.)

PR 33473
* elflink.x (_bfd_elf_gc_mark_debug_special_section_group): Don't
segfault on empty group.
* elf.c (process_sht_group_entries): Return false if all
entries are invalid.

bfd/elf.c
bfd/elflink.c

index d51552e2a2da45fe6244e90234df7bd542801a1d..33c2d269a9c6d371d2f2ae1409281e1783a838ce 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -790,7 +790,7 @@ process_sht_group_entries (bfd *abfd,
     }
 
   free (contents);
-  return true;
+  return last_elt != NULL;
 }
 
 bool
index 96497ac1c33d7980e3412dc92d22966b7909caa6..60a0a0efd8843960f3d69881f68f44559d944c7a 100644 (file)
@@ -14192,7 +14192,7 @@ _bfd_elf_gc_mark_debug_special_section_group (asection *grp)
   /* First scan to see if group contains any section other than debug
      and special section.  */
   ssec = msec = elf_next_in_group (grp);
-  do
+  while (msec != NULL)
     {
       if ((msec->flags & SEC_DEBUGGING) == 0)
        is_debug_grp = false;
@@ -14201,19 +14201,22 @@ _bfd_elf_gc_mark_debug_special_section_group (asection *grp)
        is_special_grp = false;
 
       msec = elf_next_in_group (msec);
+      if (msec == ssec)
+       break;
     }
-  while (msec != ssec);
 
   /* If this is a pure debug section group or pure special section group,
      keep all sections in this group.  */
   if (is_debug_grp || is_special_grp)
     {
-      do
+      msec = ssec;
+      while (msec != NULL)
        {
          msec->gc_mark = 1;
          msec = elf_next_in_group (msec);
+         if (msec == ssec)
+           break;
        }
-      while (msec != ssec);
     }
 }