aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2014-11-11 15:34:27 +0000
committerNick Clifton <nickc@redhat.com>2014-11-11 15:34:27 +0000
commit201159ecec7e17600df4153e5d4e7a145f0c7cfe (patch)
tree328d0499e8bedc423bb8907ad53e30f7647f2df1 /bfd/elf.c
parent015de6884f6fdebaffd4b7d4c7f14fb4d5fc0bb1 (diff)
downloadbinutils-201159ecec7e17600df4153e5d4e7a145f0c7cfe.zip
binutils-201159ecec7e17600df4153e5d4e7a145f0c7cfe.tar.gz
binutils-201159ecec7e17600df4153e5d4e7a145f0c7cfe.tar.bz2
More fixes for invalid memory accesses, uncovered by valgrind and binary fuzzers.
PR binutils/17512 * coffcode.h (coff_slurp_line_table): Initialise the parts of the line number cache that would not be initialised by the copy from the new line number table. (coff_classify_symbol): Allow for _bfd_coff_internal_syment_name returning NULL. * coffgen.c (coff_get_normalized_symbols): Get the external symbols before allocating space for the internal symbols, in case the get fails. * elf.c (_bfd_elf_slurp_version_tables): Only allocate a verref array if one is needed. Likewise with the verdef array. * peXXigen.c (_bfd_XXi_swap_sym_in): Replace abort()'s with error messages. (_bfd_XXi_swap_aux_in): Make sure that all fields of the aux structure are initialised. (pe_print_edata): Avoid reading off the end of the data buffer.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 9c4dcdf..8b207ad 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7269,8 +7269,12 @@ _bfd_elf_slurp_version_tables (bfd *abfd, bfd_boolean default_imported_symver)
hdr = &elf_tdata (abfd)->dynverref_hdr;
- elf_tdata (abfd)->verref = (Elf_Internal_Verneed *)
+ if (hdr->sh_info)
+ elf_tdata (abfd)->verref = (Elf_Internal_Verneed *)
bfd_zalloc2 (abfd, hdr->sh_info, sizeof (Elf_Internal_Verneed));
+ else
+ elf_tdata (abfd)->verref = NULL;
+
if (elf_tdata (abfd)->verref == NULL)
goto error_return;
@@ -7430,8 +7434,12 @@ error_return_verref:
else
freeidx = ++maxidx;
}
- elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *)
+ if (maxidx)
+ elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *)
bfd_zalloc2 (abfd, maxidx, sizeof (Elf_Internal_Verdef));
+ else
+ elf_tdata (abfd)->verdef = NULL;
+
if (elf_tdata (abfd)->verdef == NULL)
goto error_return;
@@ -7572,16 +7580,12 @@ asymbol *
_bfd_elf_make_empty_symbol (bfd *abfd)
{
elf_symbol_type *newsym;
- bfd_size_type amt = sizeof (elf_symbol_type);
- newsym = (elf_symbol_type *) bfd_zalloc (abfd, amt);
+ newsym = (elf_symbol_type *) bfd_zalloc (abfd, sizeof * newsym);
if (!newsym)
return NULL;
- else
- {
- newsym->symbol.the_bfd = abfd;
- return &newsym->symbol;
- }
+ newsym->symbol.the_bfd = abfd;
+ return &newsym->symbol;
}
void