From: Alan Modra Date: Mon, 24 Nov 2025 08:16:35 +0000 (+1030) Subject: PR 33473 SEGV in _bfd_elf_gc_mark_debug_special_section_group X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e397ea9446b3dca3cbc85b6c0e0158042548f19;p=thirdparty%2Fbinutils-gdb.git PR 33473 SEGV in _bfd_elf_gc_mark_debug_special_section_group 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. --- diff --git a/bfd/elf.c b/bfd/elf.c index d51552e2a2d..33c2d269a9c 100644 --- 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 diff --git a/bfd/elflink.c b/bfd/elflink.c index 96497ac1c33..60a0a0efd88 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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); } }