]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
objcopy: check input flavor before setting PE/COFF section alignment
authorJan Beulich <jbeulich@suse.com>
Fri, 26 Apr 2024 12:23:14 +0000 (14:23 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 26 Apr 2024 12:23:14 +0000 (14:23 +0200)
coff_section_data() and elf_section_data() use the same underlying
field. The pointer being non-NULL therefore isn't sufficient to know
that pei_section_data() can validly be used on the incoming object.
Apparently in 64-bit-host builds the resulting memory corruption is
benign, whereas in 32-bit-host builds a segmentation fault occurs upon
de-referencing pei_section_data()'s return value.

binutils/objcopy.c

index e8ca1374935e1a048bcf8746a919e221f405cef5..26f9d4a0f262f5b437172cb31e9ad5a5b4ea14ce 100644 (file)
@@ -4317,6 +4317,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
   if (p != NULL)
     alignment = p->alignment;
   else if (pe_section_alignment != (bfd_vma) -1
+          && bfd_get_flavour (ibfd) == bfd_target_coff_flavour
           && bfd_get_flavour (obfd) == bfd_target_coff_flavour)
     {
       alignment = power_of_two (pe_section_alignment);