]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd_elf_set_group_contents assertion
authorAlan Modra <amodra@gmail.com>
Wed, 17 Aug 2022 07:44:16 +0000 (17:14 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 17 Aug 2022 07:59:42 +0000 (17:29 +0930)
objcopy of broken SHT_GROUP sections shouldn't write garbage.

* elf.c (bfd_elf_set_group_contents): If number of entries is
unexpected, fill out section with zeros.

bfd/elf.c

index 2e01d7e9a44d9b065d6841263be675740c6c7b19..35aa45e3b90f27a6082307c61b8b3ea8dd2f9b6f 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3614,7 +3614,12 @@ bfd_elf_set_group_contents (bfd *abfd, asection *sec, void *failedptrarg)
     }
 
   loc -= 4;
-  BFD_ASSERT (loc == sec->contents);
+  if (loc != sec->contents)
+    {
+      BFD_ASSERT (0);
+      memset (sec->contents + 4, 0, loc - sec->contents);
+      loc = sec->contents;
+    }
 
   H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc);
 }