X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf-attrs.c;h=dfdf1a5311ee25f5b629cc742c7e7e2ee12d63f5;hb=9793eb77929a4ab2c0192d9bf5d3f8d20dd17394;hp=8819f8e4a0eabc83da6c45747bc0563a5541271e;hpb=6f2750feaf2827ef8a1a0a5b2f90c1e9a6cabbd1;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c index 8819f8e4a0..dfdf1a5311 100644 --- a/bfd/elf-attrs.c +++ b/bfd/elf-attrs.c @@ -1,5 +1,5 @@ /* ELF attributes support (based on ARM EABI attributes). - Copyright (C) 2005-2016 Free Software Foundation, Inc. + Copyright (C) 2005-2018 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -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; @@ -468,6 +470,13 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) if (section_len > len) section_len = len; len -= section_len; + if (section_len <= 4) + { + _bfd_error_handler + (_("%pB: error: attribute section length too small: %" PRId64), + abfd, (int64_t) section_len); + break; + } section_len -= 4; namelen = strnlen ((char *) p, section_len) + 1; if (namelen == 0 || namelen >= section_len) @@ -493,7 +502,7 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) bfd_vma subsection_len; bfd_byte *end; - tag = safe_read_leb128 (abfd, p, &n, FALSE, p_end); + tag = _bfd_safe_read_leb128 (abfd, p, &n, FALSE, p_end); p += n; if (p < p_end - 4) subsection_len = bfd_get_32 (abfd, p); @@ -517,13 +526,13 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) { int type; - tag = safe_read_leb128 (abfd, p, &n, FALSE, end); + tag = _bfd_safe_read_leb128 (abfd, p, &n, FALSE, end); p += n; type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag); switch (type & (ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL)) { case ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL: - val = safe_read_leb128 (abfd, p, &n, FALSE, end); + val = _bfd_safe_read_leb128 (abfd, p, &n, FALSE, end); p += n; bfd_elf_add_obj_attr_int_string (abfd, vendor, tag, val, (char *) p); @@ -535,7 +544,7 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) p += strlen ((char *)p) + 1; break; case ATTR_TYPE_FLAG_INT_VAL: - val = safe_read_leb128 (abfd, p, &n, FALSE, end); + val = _bfd_safe_read_leb128 (abfd, p, &n, FALSE, end); p += n; bfd_elf_add_obj_attr_int (abfd, vendor, tag, val); break; @@ -571,8 +580,9 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) attributes. */ bfd_boolean -_bfd_elf_merge_object_attributes (bfd *ibfd, bfd *obfd) +_bfd_elf_merge_object_attributes (bfd *ibfd, struct bfd_link_info *info) { + bfd *obfd = info->output_bfd; obj_attribute *in_attr; obj_attribute *out_attr; int vendor; @@ -590,7 +600,8 @@ _bfd_elf_merge_object_attributes (bfd *ibfd, bfd *obfd) if (in_attr->i > 0 && strcmp (in_attr->s, "gnu") != 0) { _bfd_error_handler - (_("error: %B: Object has vendor-specific contents that " + /* xgettext:c-format */ + (_("error: %pB: object has vendor-specific contents that " "must be processed by the '%s' toolchain"), ibfd, in_attr->s); return FALSE; @@ -599,7 +610,8 @@ _bfd_elf_merge_object_attributes (bfd *ibfd, bfd *obfd) if (in_attr->i != out_attr->i || (in_attr->i != 0 && strcmp (in_attr->s, out_attr->s) != 0)) { - _bfd_error_handler (_("error: %B: Object tag '%d, %s' is " + /* xgettext:c-format */ + _bfd_error_handler (_("error: %pB: object tag '%d, %s' is " "incompatible with tag '%d, %s'"), ibfd, in_attr->i, in_attr->s ? in_attr->s : "",