diff options
author | Nick Clifton <nickc@redhat.com> | 2017-09-01 09:57:44 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2017-09-01 09:57:44 +0100 |
commit | 2a143b99fc4a5094a9cf128f3184d8e6818c8229 (patch) | |
tree | c455ccc93d2be39f8cf67c440e815b6efcfa1e7f /bfd/elf-attrs.c | |
parent | 5c811d30d12b6f7c6c6f4ce6d03408d987154548 (diff) | |
download | gdb-2a143b99fc4a5094a9cf128f3184d8e6818c8229.zip gdb-2a143b99fc4a5094a9cf128f3184d8e6818c8229.tar.gz gdb-2a143b99fc4a5094a9cf128f3184d8e6818c8229.tar.bz2 |
Fix buffer overrun when parsing an ELF attribute string that is not NUL terminated.
PR 22058
* elf-attrs.c (_bfd_elf_parse_attributes): Ensure that the
attribute buffer is NUL terminated.
Diffstat (limited to 'bfd/elf-attrs.c')
-rw-r--r-- | bfd/elf-attrs.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c index 759da6e..761a4ce 100644 --- a/bfd/elf-attrs.c +++ b/bfd/elf-attrs.c @@ -438,7 +438,7 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) /* PR 17512: file: 2844a11d. */ if (hdr->sh_size == 0) return; - contents = (bfd_byte *) bfd_malloc (hdr->sh_size); + contents = (bfd_byte *) bfd_malloc (hdr->sh_size + 1); if (!contents) return; if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0, @@ -447,6 +447,8 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) free (contents); return; } + /* Ensure that the buffer is NUL terminated. */ + contents[hdr->sh_size] = 0; p = contents; p_end = p + hdr->sh_size; std_sec = get_elf_backend_data (abfd)->obj_attrs_vendor; |