|
|
861f93 |
2007-09-23 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
|
861f93 |
|
|
|
861f93 |
* elfcode.h (NAME(_bfd_elf,bfd_from_remote_memory)): New variables
|
|
|
861f93 |
X_SHDR_SHSTRTAB and I_SHDR_SHSTRTAB. Fixed the CONTENTS_SIZE trimming
|
|
|
861f93 |
check for its aligned size between the last segment and still before
|
|
|
861f93 |
the section header end. Added variables check to cover also the
|
|
|
861f93 |
section header string table.
|
|
|
861f93 |
|
|
|
861f93 |
--- gdb-7.4.50.20120120-orig/bfd/elfcode.h 2012-02-29 09:17:08.000000000 +0100
|
|
|
861f93 |
+++ gdb-7.4.50.20120120/bfd/elfcode.h 2012-02-29 10:23:03.000000000 +0100
|
|
|
861f93 |
@@ -1621,6 +1621,8 @@ NAME(_bfd_elf,bfd_from_remote_memory)
|
|
|
861f93 |
Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
|
|
|
861f93 |
Elf_External_Phdr *x_phdrs;
|
|
|
861f93 |
Elf_Internal_Phdr *i_phdrs, *last_phdr;
|
|
|
861f93 |
+ Elf_External_Shdr *x_shdrs;
|
|
|
861f93 |
+ Elf_Internal_Shdr *i_shdrs;
|
|
|
861f93 |
bfd *nbfd;
|
|
|
861f93 |
struct bfd_in_memory *bim;
|
|
|
861f93 |
int contents_size;
|
|
|
861f93 |
@@ -1740,24 +1742,46 @@ NAME(_bfd_elf,bfd_from_remote_memory)
|
|
|
861f93 |
|
|
|
861f93 |
/* Trim the last segment so we don't bother with zeros in the last page
|
|
|
861f93 |
that are off the end of the file. However, if the extra bit in that
|
|
|
861f93 |
- page includes the section headers, keep them. */
|
|
|
861f93 |
- if ((bfd_vma) contents_size > last_phdr->p_offset + last_phdr->p_filesz
|
|
|
861f93 |
- && (bfd_vma) contents_size >= (i_ehdr.e_shoff
|
|
|
861f93 |
- + i_ehdr.e_shnum * i_ehdr.e_shentsize))
|
|
|
861f93 |
+ page includes the section headers os the section header string table,
|
|
|
861f93 |
+ keep them. */
|
|
|
861f93 |
+ if ((bfd_vma) contents_size > last_phdr->p_offset + last_phdr->p_filesz)
|
|
|
861f93 |
+ contents_size = last_phdr->p_offset + last_phdr->p_filesz;
|
|
|
861f93 |
+
|
|
|
861f93 |
+ if ((bfd_vma) contents_size < i_ehdr.e_shoff
|
|
|
861f93 |
+ + i_ehdr.e_shnum * i_ehdr.e_shentsize)
|
|
|
861f93 |
+ contents_size = i_ehdr.e_shoff + i_ehdr.e_shnum * i_ehdr.e_shentsize;
|
|
|
861f93 |
+
|
|
|
861f93 |
+ /* Verify also all the sections fit into CONTENTS_SIZE. */
|
|
|
861f93 |
+
|
|
|
861f93 |
+ x_shdrs = bfd_malloc (i_ehdr.e_shnum * (sizeof *x_shdrs + sizeof *i_shdrs));
|
|
|
861f93 |
+ if (x_shdrs == NULL)
|
|
|
861f93 |
{
|
|
|
861f93 |
- contents_size = last_phdr->p_offset + last_phdr->p_filesz;
|
|
|
861f93 |
- if ((bfd_vma) contents_size < (i_ehdr.e_shoff
|
|
|
861f93 |
- + i_ehdr.e_shnum * i_ehdr.e_shentsize))
|
|
|
861f93 |
- contents_size = i_ehdr.e_shoff + i_ehdr.e_shnum * i_ehdr.e_shentsize;
|
|
|
861f93 |
+ free (x_phdrs);
|
|
|
861f93 |
+ bfd_set_error (bfd_error_no_memory);
|
|
|
861f93 |
+ return NULL;
|
|
|
861f93 |
}
|
|
|
861f93 |
+ err = target_read_memory (ehdr_vma + i_ehdr.e_shoff, (bfd_byte *) x_shdrs,
|
|
|
861f93 |
+ i_ehdr.e_shnum * sizeof *x_shdrs);
|
|
|
861f93 |
+ if (err)
|
|
|
861f93 |
+ i_shdrs = NULL;
|
|
|
861f93 |
else
|
|
|
861f93 |
- contents_size = last_phdr->p_offset + last_phdr->p_filesz;
|
|
|
861f93 |
+ {
|
|
|
861f93 |
+ i_shdrs = (Elf_Internal_Shdr *) &x_shdrs[i_ehdr.e_shnum];
|
|
|
861f93 |
+ for (i = 0; i < i_ehdr.e_shnum; ++i)
|
|
|
861f93 |
+ {
|
|
|
861f93 |
+ elf_swap_shdr_in (templ, &x_shdrs[i], &i_shdrs[i]);
|
|
|
861f93 |
+
|
|
|
861f93 |
+ if ((bfd_vma) contents_size < i_shdrs[i].sh_offset + i_shdrs[i].sh_size)
|
|
|
861f93 |
+ contents_size = i_shdrs[i].sh_offset + i_shdrs[i].sh_size;
|
|
|
861f93 |
+ }
|
|
|
861f93 |
+ }
|
|
|
861f93 |
|
|
|
861f93 |
/* Now we know the size of the whole image we want read in. */
|
|
|
861f93 |
contents = (bfd_byte *) bfd_zmalloc (contents_size);
|
|
|
861f93 |
if (contents == NULL)
|
|
|
861f93 |
{
|
|
|
861f93 |
free (x_phdrs);
|
|
|
861f93 |
+ free (x_shdrs);
|
|
|
861f93 |
bfd_set_error (bfd_error_no_memory);
|
|
|
861f93 |
return NULL;
|
|
|
861f93 |
}
|
|
|
861f93 |
@@ -1776,6 +1800,7 @@ NAME(_bfd_elf,bfd_from_remote_memory)
|
|
|
861f93 |
if (err)
|
|
|
861f93 |
{
|
|
|
861f93 |
free (x_phdrs);
|
|
|
861f93 |
+ free (x_shdrs);
|
|
|
861f93 |
free (contents);
|
|
|
861f93 |
bfd_set_error (bfd_error_system_call);
|
|
|
861f93 |
errno = err;
|
|
|
861f93 |
@@ -1784,10 +1809,32 @@ NAME(_bfd_elf,bfd_from_remote_memory)
|
|
|
861f93 |
}
|
|
|
861f93 |
free (x_phdrs);
|
|
|
861f93 |
|
|
|
861f93 |
- /* If the segments visible in memory didn't include the section headers,
|
|
|
861f93 |
+ if (i_shdrs)
|
|
|
861f93 |
+ {
|
|
|
861f93 |
+ memcpy (contents + i_ehdr.e_shoff, x_shdrs,
|
|
|
861f93 |
+ i_ehdr.e_shnum * sizeof *x_shdrs);
|
|
|
861f93 |
+
|
|
|
861f93 |
+ for (i = 0; i < i_ehdr.e_shnum; ++i)
|
|
|
861f93 |
+ {
|
|
|
861f93 |
+ bfd_vma start = i_shdrs[i].sh_offset;
|
|
|
861f93 |
+ bfd_vma end = i_shdrs[i].sh_offset + i_shdrs[i].sh_size;
|
|
|
861f93 |
+
|
|
|
861f93 |
+ if (end > (bfd_vma) contents_size)
|
|
|
861f93 |
+ end = contents_size;
|
|
|
861f93 |
+ err = target_read_memory (ehdr_vma + start, contents + start,
|
|
|
861f93 |
+ end - start);
|
|
|
861f93 |
+ if (err)
|
|
|
861f93 |
+ {
|
|
|
861f93 |
+ i_shdrs = NULL;
|
|
|
861f93 |
+ break;
|
|
|
861f93 |
+ }
|
|
|
861f93 |
+ }
|
|
|
861f93 |
+ }
|
|
|
861f93 |
+ free (x_shdrs);
|
|
|
861f93 |
+
|
|
|
861f93 |
+ /* If the segments readable in memory didn't include the section headers,
|
|
|
861f93 |
then clear them from the file header. */
|
|
|
861f93 |
- if ((bfd_vma) contents_size < (i_ehdr.e_shoff
|
|
|
861f93 |
- + i_ehdr.e_shnum * i_ehdr.e_shentsize))
|
|
|
861f93 |
+ if (i_shdrs == NULL)
|
|
|
861f93 |
{
|
|
|
861f93 |
memset (&x_ehdr.e_shoff, 0, sizeof x_ehdr.e_shoff);
|
|
|
861f93 |
memset (&x_ehdr.e_shnum, 0, sizeof x_ehdr.e_shnum);
|