aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2020-03-06 10:09:22 +0000
committerNick Clifton <nickc@redhat.com>2020-03-06 10:09:22 +0000
commita0dcf2970562c19140460a07b2c987714639cd7b (patch)
tree67161a1ca585012f45c4b117bb9ecbd8bbc17740 /bfd
parentbc49bfd849a9291b61bbe314505a35d07e130347 (diff)
downloadfsf-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')
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/elf.c40
2 files changed, 38 insertions, 7 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 838b07f..0df437b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-06 Nick Clifton <nickc@redhat.com>
+
+ * elf.c (_bfd_elf_set_section_contents): Replace call to abort
+ with error messages and failure return values.
+
2020-03-05 Max Filippov <jcmvbkbc@gmail.com>
* elf32-xtensa.c (shrink_dynamic_reloc_sections): Shrink dynamic
diff --git a/bfd/elf.c b/bfd/elf.c
index 747d120..e6db2ff 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -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)