X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Fcoffgen.c;h=96140e0ad278d9f7559eaa3e4432bbace5c92231;hb=7e94cf6cb018df7cc1311afb2b15e9f69adb60d9;hp=20cee0a74c584281cdac0fb21617702c68d8486d;hpb=1f4361a77b18c5ab32baf2f30fefe5e301e017be;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/coffgen.c b/bfd/coffgen.c index 20cee0a74c..96140e0ad2 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -225,12 +225,12 @@ make_a_section_from_file (bfd *abfd, /* Read in a COFF object and make it into a BFD. This is used by ECOFF as well. */ -const bfd_target * +bfd_cleanup coff_real_object_p (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *); -const bfd_target * +bfd_cleanup coff_real_object_p (bfd *abfd, unsigned nscns, struct internal_filehdr *internal_f, @@ -275,13 +275,10 @@ coff_real_object_p (bfd *abfd, scnhsz = bfd_coff_scnhsz (abfd); readsize = (bfd_size_type) nscns * scnhsz; - external_sections = (char *) bfd_alloc (abfd, readsize); + external_sections = (char *) _bfd_alloc_and_read (abfd, readsize, readsize); if (!external_sections) goto fail; - if (bfd_bread ((void *) external_sections, readsize, abfd) != readsize) - goto fail; - /* Set the arch/mach *before* swapping in sections; section header swapping may depend on arch/mach info. */ if (! bfd_coff_set_arch_mach_hook (abfd, (void *) internal_f)) @@ -303,7 +300,7 @@ coff_real_object_p (bfd *abfd, } _bfd_coff_free_symbols (abfd); - return abfd->xvec; + return _bfd_no_cleanup; fail: _bfd_coff_free_symbols (abfd); @@ -312,13 +309,13 @@ coff_real_object_p (bfd *abfd, abfd->tdata.any = tdata_save; abfd->flags = oflags; abfd->start_address = ostart; - return (const bfd_target *) NULL; + return NULL; } /* Turn a COFF file into a BFD, but fail with bfd_error_wrong_format if it is not a COFF file. This is also used by ECOFF. */ -const bfd_target * +bfd_cleanup coff_object_p (bfd *abfd) { bfd_size_type filhsz; @@ -332,14 +329,11 @@ coff_object_p (bfd *abfd) filhsz = bfd_coff_filhsz (abfd); aoutsz = bfd_coff_aoutsz (abfd); - filehdr = bfd_alloc (abfd, filhsz); + filehdr = _bfd_alloc_and_read (abfd, filhsz, filhsz); if (filehdr == NULL) - return NULL; - if (bfd_bread (filehdr, filhsz, abfd) != filhsz) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); - bfd_release (abfd, filehdr); return NULL; } bfd_coff_swap_filehdr_in (abfd, filehdr, &internal_f); @@ -365,18 +359,13 @@ coff_object_p (bfd *abfd) { void * opthdr; - opthdr = bfd_alloc (abfd, aoutsz); + opthdr = _bfd_alloc_and_read (abfd, aoutsz, internal_f.f_opthdr); if (opthdr == NULL) return NULL; - if (bfd_bread (opthdr, (bfd_size_type) internal_f.f_opthdr, abfd) - != internal_f.f_opthdr) - { - bfd_release (abfd, opthdr); - return NULL; - } /* PR 17512: file: 11056-1136-0.004. */ if (internal_f.f_opthdr < aoutsz) - memset (((char *) opthdr) + internal_f.f_opthdr, 0, aoutsz - internal_f.f_opthdr); + memset (((char *) opthdr) + internal_f.f_opthdr, 0, + aoutsz - internal_f.f_opthdr); bfd_coff_swap_aouthdr_in (abfd, opthdr, (void *) &internal_a); bfd_release (abfd, opthdr); @@ -1593,19 +1582,20 @@ build_debug_section (bfd *abfd, asection ** sect_return) return NULL; } - sec_size = sect->size; - debug_section = (char *) bfd_alloc (abfd, sec_size); - if (debug_section == NULL) - return NULL; - /* Seek to the beginning of the `.debug' section and read it. Save the current position first; it is needed by our caller. Then read debug section and reset the file pointer. */ position = bfd_tell (abfd); - if (bfd_seek (abfd, sect->filepos, SEEK_SET) != 0 - || bfd_bread (debug_section, sec_size, abfd) != sec_size - || bfd_seek (abfd, position, SEEK_SET) != 0) + if (bfd_seek (abfd, sect->filepos, SEEK_SET) != 0) + return NULL; + + sec_size = sect->size; + debug_section = (char *) _bfd_alloc_and_read (abfd, sec_size, sec_size); + if (debug_section == NULL) + return NULL; + + if (bfd_seek (abfd, position, SEEK_SET) != 0) return NULL; * sect_return = sect; @@ -1642,47 +1632,25 @@ _bfd_coff_get_external_symbols (bfd *abfd) size_t symesz; size_t size; void * syms; - ufile_ptr filesize; if (obj_coff_external_syms (abfd) != NULL) return TRUE; - /* Check for integer overflow and for unreasonable symbol counts. */ - filesize = bfd_get_file_size (abfd); symesz = bfd_coff_symesz (abfd); - if (_bfd_mul_overflow (obj_raw_syment_count (abfd), symesz, &size) - || (filesize != 0 && size > filesize)) + if (_bfd_mul_overflow (obj_raw_syment_count (abfd), symesz, &size)) { bfd_set_error (bfd_error_file_truncated); - _bfd_error_handler (_("%pB: corrupt symbol count: %#" PRIx64 ""), - abfd, (uint64_t) obj_raw_syment_count (abfd)); return FALSE; } if (size == 0) return TRUE; - syms = bfd_malloc (size); - if (syms == NULL) - { - /* PR 21013: Provide an error message when the alloc fails. */ - _bfd_error_handler (_("%pB: not enough memory to allocate space " - "for %#" PRIx64 " symbols of size %#" PRIx64), - abfd, (uint64_t) obj_raw_syment_count (abfd), - (uint64_t) symesz); - return FALSE; - } - - if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0 - || bfd_bread (syms, size, abfd) != size) - { - if (syms != NULL) - free (syms); - return FALSE; - } - + if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0) + return FALSE; + syms = _bfd_malloc_and_read (abfd, size, size); obj_coff_external_syms (abfd) = syms; - return TRUE; + return syms != NULL; } /* Read in the external strings. The strings are not loaded until @@ -1850,6 +1818,13 @@ coff_get_normalized_symtab (bfd *abfd) symbol_ptr = internal_ptr; internal_ptr->is_sym = TRUE; + /* PR 17512: Prevent buffer overrun. */ + if (symbol_ptr->u.syment.n_numaux > (raw_end - raw_src) / symesz) + { + bfd_release (abfd, internal); + return NULL; + } + for (i = 0; i < symbol_ptr->u.syment.n_numaux; i++) @@ -1857,13 +1832,6 @@ coff_get_normalized_symtab (bfd *abfd) internal_ptr++; raw_src += symesz; - /* PR 17512: Prevent buffer overrun. */ - if (raw_src >= raw_end || internal_ptr >= internal_end) - { - bfd_release (abfd, internal); - return NULL; - } - bfd_coff_swap_aux_in (abfd, (void *) raw_src, symbol_ptr->u.syment.n_type, symbol_ptr->u.syment.n_sclass,