This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Fix buffer overrun when parsing an ELF attribute string that is not NUL terminated.
- From: Nick Clifton <nickc at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 1 Sep 2017 08:58:27 -0000
- Subject: [binutils-gdb] Fix buffer overrun when parsing an ELF attribute string that is not NUL terminated.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2a143b99fc4a5094a9cf128f3184d8e6818c8229
commit 2a143b99fc4a5094a9cf128f3184d8e6818c8229
Author: Nick Clifton <nickc@redhat.com>
Date: Fri Sep 1 09:57:44 2017 +0100
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:
---
bfd/ChangeLog | 6 ++++++
bfd/elf-attrs.c | 4 +++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 368b558..e0dd88f 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2017-09-01 Nick Clifton <nickc@redhat.com>
+
+ PR 22058
+ * elf-attrs.c (_bfd_elf_parse_attributes): Ensure that the
+ attribute buffer is NUL terminated.
+
2017-08-31 Nick Clifton <nickc@redhat.com>
PR 22047
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;