diff options
author | Nick Clifton <nickc@redhat.com> | 2020-03-06 10:09:22 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2020-03-06 10:09:22 +0000 |
commit | a0dcf2970562c19140460a07b2c987714639cd7b (patch) | |
tree | 67161a1ca585012f45c4b117bb9ecbd8bbc17740 /bfd/elf.c | |
parent | bc49bfd849a9291b61bbe314505a35d07e130347 (diff) | |
download | fsf-binutils-gdb-a0dcf2970562c19140460a07b2c987714639cd7b.zip fsf-binutils-gdb-a0dcf2970562c19140460a07b2c987714639cd7b.tar.gz fsf-binutils-gdb-a0dcf2970562c19140460a07b2c987714639cd7b.tar.bz2 |
Fix an abort triggered when objcopy is used to set the "share" section flag on an ELF section.
binutils* objcopy.c (check_new_section_flags): New function. Reject the
SEC_COFF_SHARED flag if the target is not a COFF binary.
(copy_object): Call check_new_section_flags.
(setup_section): Likewise.
* doc/binutils.texi (objcopy): Add a note that the 'share' section
flag cannot be applied to ELF binaries.
bfd * elf.c (_bfd_elf_set_section_contents): Replace call to abort
with error messages and failure return values.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 40 |
1 files changed, 33 insertions, 7 deletions
@@ -3218,7 +3218,6 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) /* Set SEC_ELF_COMPRESS to indicate this section should be compressed. */ asect->flags |= SEC_ELF_COMPRESS; - /* If this section will be compressed, delay adding section name to section name section after it is compressed in _bfd_elf_assign_file_positions_for_non_load. */ @@ -9181,20 +9180,47 @@ _bfd_elf_set_section_contents (bfd *abfd, hdr = &elf_section_data (section)->this_hdr; if (hdr->sh_offset == (file_ptr) -1) { + unsigned char *contents; + if (bfd_section_is_ctf (section)) /* Nothing to do with this section: the contents are generated later. */ return TRUE; - /* We must compress this section. Write output to the buffer. */ - unsigned char *contents = hdr->contents; - if ((offset + count) > hdr->sh_size - || (section->flags & SEC_ELF_COMPRESS) == 0 - || contents == NULL) - abort (); + if ((section->flags & SEC_ELF_COMPRESS) == 0) + { + _bfd_error_handler + (_("%pB:%pA: error: attempting to write into an unallocated compressed section"), + abfd, section); + bfd_set_error (bfd_error_invalid_operation); + return FALSE; + } + + if ((offset + count) > hdr->sh_size) + { + _bfd_error_handler + (_("%pB:%pA: error: attempting to write over the end of the section"), + abfd, section); + + bfd_set_error (bfd_error_invalid_operation); + return FALSE; + } + + contents = hdr->contents; + if (contents == NULL) + { + _bfd_error_handler + (_("%pB:%pA: error: attempting to write section into an empty buffer"), + abfd, section); + + bfd_set_error (bfd_error_invalid_operation); + return FALSE; + } + memcpy (contents + offset, location, count); return TRUE; } + pos = hdr->sh_offset + offset; if (bfd_seek (abfd, pos, SEEK_SET) != 0 || bfd_bwrite (location, count, abfd) != count) |