From: Nick Clifton Date: Fri, 1 Sep 2017 08:59:17 +0000 (+0100) Subject: Fix buffer overrun when parsing an ELF attribute string that is not NUL terminated. X-Git-Tag: binutils-2_29_1~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aceaeff8140af6ba50469e8b63d664cc91e5485b;p=thirdparty%2Fbinutils-gdb.git 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. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 7d997fde558..e9ea6cfdda3 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2017-09-01 Nick Clifton + + PR 22058 + * elf-attrs.c (_bfd_elf_parse_attributes): Ensure that the + attribute buffer is NUL terminated. + 2017-08-30 Maciej W. Rozycki * elfxx-mips.c (mips_elf_perform_relocation): Correct microMIPS diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c index def1345eeb0..02105433b6b 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;