X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felfcore.h;h=c0cdceba42a4f7d03514bebb210190b18ada2a74;hb=415c8100a28d56628c01730ef279c61f99578518;hp=1279327bf0d333fdba6f1b7ff0deafa6a073c17d;hpb=864619bb2e68e4ec8fa5bcfc87b00bf6667601e3;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elfcore.h b/bfd/elfcore.h index 1279327bf0..c0cdceba42 100644 --- a/bfd/elfcore.h +++ b/bfd/elfcore.h @@ -1,5 +1,5 @@ /* ELF core file support for BFD. - Copyright (C) 1995-2019 Free Software Foundation, Inc. + Copyright (C) 1995-2021 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -36,7 +36,7 @@ elf_core_file_pid (bfd *abfd) return elf_tdata (abfd)->core->pid; } -bfd_boolean +bool elf_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd) { char* corename; @@ -46,7 +46,7 @@ elf_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd) if (core_bfd->xvec != exec_bfd->xvec) { bfd_set_error (bfd_error_system_call); - return FALSE; + return false; } /* If both BFDs have identical build-ids, then they match. */ @@ -55,21 +55,21 @@ elf_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd) && core_bfd->build_id->size == exec_bfd->build_id->size && memcmp (core_bfd->build_id->data, exec_bfd->build_id->data, core_bfd->build_id->size) == 0) - return TRUE; + return true; /* See if the name in the corefile matches the executable name. */ corename = elf_tdata (core_bfd)->core->program; if (corename != NULL) { - const char* execname = strrchr (exec_bfd->filename, '/'); + const char* execname = strrchr (bfd_get_filename (exec_bfd), '/'); - execname = execname ? execname + 1 : exec_bfd->filename; + execname = execname ? execname + 1 : bfd_get_filename (exec_bfd); if (strcmp (execname, corename) != 0) - return FALSE; + return false; } - return TRUE; + return true; } /* Core files are simply standard ELF formatted files that partition @@ -83,7 +83,7 @@ elf_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd) that allow standard bfd access to the general registers (.reg) and the floating point registers (.reg2). */ -const bfd_target * +bfd_cleanup elf_core_file_p (bfd *abfd) { Elf_External_Ehdr x_ehdr; /* Elf file header, external form. */ @@ -314,11 +314,11 @@ elf_core_file_p (bfd *abfd) /* Save the entry point from the ELF header. */ abfd->start_address = i_ehdrp->e_entry; - return abfd->xvec; + return _bfd_no_cleanup; -wrong: + wrong: bfd_set_error (bfd_error_wrong_format); -fail: + fail: return NULL; } @@ -326,7 +326,7 @@ fail: OFFSET is the file offset to a PT_LOAD segment that may contain the build-id note. Returns TRUE upon success, FALSE otherwise. */ -bfd_boolean +bool NAME(_bfd_elf, core_find_build_id) (bfd *abfd, bfd_vma offset) @@ -335,6 +335,7 @@ NAME(_bfd_elf, core_find_build_id) Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form. */ Elf_Internal_Phdr *i_phdr; unsigned int i; + size_t amt; /* Seek to the position of the segment at OFFSET. */ if (bfd_seek (abfd, offset, SEEK_SET) != 0) @@ -384,8 +385,12 @@ NAME(_bfd_elf, core_find_build_id) goto fail; /* Read in program headers. */ - i_phdr = (Elf_Internal_Phdr *) bfd_alloc2 (abfd, i_ehdr.e_phnum, - sizeof (*i_phdr)); + if (_bfd_mul_overflow (i_ehdr.e_phnum, sizeof (*i_phdr), &amt)) + { + bfd_set_error (bfd_error_file_too_big); + goto fail; + } + i_phdr = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt); if (i_phdr == NULL) goto fail; @@ -405,8 +410,15 @@ NAME(_bfd_elf, core_find_build_id) { elf_read_notes (abfd, offset + i_phdr->p_offset, i_phdr->p_filesz, i_phdr->p_align); + + /* Make sure ABFD returns to processing the program headers. */ + if (bfd_seek (abfd, (file_ptr) (offset + i_ehdr.e_phoff + + (i + 1) * sizeof (x_phdr)), + SEEK_SET) != 0) + goto fail; + if (abfd->build_id != NULL) - return TRUE; + return true; } } @@ -414,8 +426,8 @@ NAME(_bfd_elf, core_find_build_id) build-id was found. */ goto fail; -wrong: + wrong: bfd_set_error (bfd_error_wrong_format); -fail: - return FALSE; + fail: + return false; }