aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfcore.h
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2008-05-10 01:58:17 +0000
committerAlan Modra <amodra@gmail.com>2008-05-10 01:58:17 +0000
commit536d0ff40ed48b72865992abe1a69c1b3eb46201 (patch)
tree960d7e734537f442211befce7ace1084f4fa7d9b /bfd/elfcore.h
parent14a720a13304b55e9ccc30c628a0f096250fc360 (diff)
downloadgdb-536d0ff40ed48b72865992abe1a69c1b3eb46201.zip
gdb-536d0ff40ed48b72865992abe1a69c1b3eb46201.tar.gz
gdb-536d0ff40ed48b72865992abe1a69c1b3eb46201.tar.bz2
* elfcore.h (elf_core_file_p): Warn about core truncation.
Diffstat (limited to 'bfd/elfcore.h')
-rw-r--r--bfd/elfcore.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/bfd/elfcore.h b/bfd/elfcore.h
index dbf9397..9c51422 100644
--- a/bfd/elfcore.h
+++ b/bfd/elfcore.h
@@ -1,6 +1,6 @@
/* ELF core file support for BFD.
- Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2007
- Free Software Foundation, Inc.
+ Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2007,
+ 2008 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
@@ -227,6 +227,32 @@ elf_core_file_p (bfd *abfd)
if (! bfd_section_from_phdr (abfd, i_phdrp + phindex, (int) phindex))
goto fail;
+ /* Check for core truncation. */
+ {
+ bfd_size_type high = 0;
+ struct stat statbuf;
+ for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex)
+ {
+ Elf_Internal_Phdr *p = i_phdrp + phindex;
+ if (p->p_filesz)
+ {
+ bfd_size_type current = p->p_offset + p->p_filesz;
+ if (high < current)
+ high = current;
+ }
+ }
+ if (bfd_stat (abfd, &statbuf) == 0)
+ {
+ if ((bfd_size_type) statbuf.st_size < high)
+ {
+ (*_bfd_error_handler)
+ (_("Warning: %B is truncated: expected core file "
+ "size >= %lu, found: %lu."),
+ abfd, (unsigned long) high, (unsigned long) statbuf.st_size);
+ }
+ }
+ }
+
/* Save the entry point from the ELF header. */
bfd_get_start_address (abfd) = i_ehdrp->e_entry;