diff options
author | Cary Coutant <ccoutant@google.com> | 2008-05-01 17:06:52 +0000 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2008-05-01 17:06:52 +0000 |
commit | 6f342c71c800fcae882cd6a69965cc531c1e38e6 (patch) | |
tree | ad80ade7dd8c92c6fd765e9c955427347d0008f8 /bfd/elf.c | |
parent | af69b57fd7320437ad61d223b769f0357889f1ef (diff) | |
download | gdb-6f342c71c800fcae882cd6a69965cc531c1e38e6.tar.gz |
* elf.c (bfd_elf_get_str_section): Fix memory leak caused by
corrupt string table.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/bfd/elf.c b/bfd/elf.c index 2f1ec37972c..1a32d427092 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -281,7 +281,7 @@ bfd_elf_get_str_section (bfd *abfd, unsigned int shindex) /* Allocate and clear an extra byte at the end, to prevent crashes in case the string table is not terminated. */ - if (shstrtabsize + 1 == 0 + if (shstrtabsize + 1 <= 1 || (shstrtab = bfd_alloc (abfd, shstrtabsize + 1)) == NULL || bfd_seek (abfd, offset, SEEK_SET) != 0) shstrtab = NULL; @@ -290,6 +290,10 @@ bfd_elf_get_str_section (bfd *abfd, unsigned int shindex) if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_file_truncated); shstrtab = NULL; + /* Once we've failed to read it, make sure we don't keep + trying. Otherwise, we'll keep allocating space for + the string table over and over. */ + i_shdrp[shindex]->sh_size = 0; } else shstrtab[shstrtabsize] = '\0'; |