summaryrefslogtreecommitdiff
path: root/binutils/objdump.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2014-12-01 16:43:46 +0000
committerNick Clifton <nickc@redhat.com>2014-12-01 16:43:46 +0000
commit06614111d1be94b43ea8dd83805184d4e177bcea (patch)
tree7b83dc3944a96259e83bf4c949b237404f02c5bb /binutils/objdump.c
parent30b5e341f3bcb219718ad32cd0065670fd37e637 (diff)
More fixes for memory access violations exposed by fuzzed binaries.
PR binutils/17512 * dwarf.h (struct dwarf_section): Add user_data field. * dwarf.c (frame_need_space): Check for an over large register number. (display_debug_frames): Check the return value from frame_need_space. Check for a CFA expression that is so long the start address wraps around. (debug_displays): Initialise the user_data field. * objdump.c (load_specific_debug_section): Save the BFD section pointer in the user_data field of the dwarf_section structure. (free_debug_section): Update BFD section data when freeing section contents. * readelf.c (load_specific_debug_section): Initialise the user_data field. * archive.c (do_slurp_coff_armap): Add range checks to prevent running off the end of the string table. * compress.c (bfd_get_full_section_contents): Return a NULL pointer for zero sized sections. Do not attempt to copy a buffer onto itself. * elf-attrs.c (_bfd_elf_parse_attributes): Check for an empty header. Add range checks to avoid running off the end of the section. * elf.c (bfd_elf_get_str_section): Seek before allocating so that if the seek fails, no memory is allocated. (bfd_elf_string_from_elf_section): Do not allocate a string from a non string section. It only leads to trouble later on. (_bfd_elf_print_private_bfd_data): Check for there being too little external dynamic data. (bfd_section_from_shdr): Replace assertion with a failure mode. (bfd_section_from_shdr): When walking a loaded group section use the internal structure size, not the external size. Check for the group section being empty. * elf32-i386.c (elf_i386_rtype_to_howto): Replace assertion with a failure mode. * elfcode.h (elf_slurp_reloc_table): Likewise. * reloc.c (bfd_perform_relocation): Avoid seg-fault if the howto parameter is NULL.
Diffstat (limited to 'binutils/objdump.c')
-rw-r--r--binutils/objdump.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c
index fdfa60250c..b13bf00e69 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -2280,6 +2280,7 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
section->address = bfd_get_section_vma (abfd, sec);
section->size = bfd_get_section_size (sec);
section->start = NULL;
+ section->user_data = sec;
ret = bfd_get_full_section_contents (abfd, sec, &section->start);
if (! ret)
@@ -2346,6 +2347,22 @@ free_debug_section (enum dwarf_section_display_enum debug)
if (section->start == NULL)
return;
+ /* PR 17512: file: 0f67f69d. */
+ if (section->user_data != NULL)
+ {
+ asection * sec = (asection *) section->user_data;
+
+ /* If we are freeing contents that are also pointed to by the BFD
+ library's section structure then make sure to update those pointers
+ too. Otherwise, the next time we try to load data for this section
+ we can end up using a stale pointer. */
+ if (section->start == sec->contents)
+ {
+ sec->contents = NULL;
+ sec->flags &= ~ SEC_IN_MEMORY;
+ }
+ }
+
free ((char *) section->start);
section->start = NULL;
section->address = 0;