aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@google.com>2008-05-01 17:06:52 +0000
committerCary Coutant <ccoutant@google.com>2008-05-01 17:06:52 +0000
commit3471d59d313d799d8c4a281114a9a12f98337b03 (patch)
tree2435d1a8d60885266df7b37d688379aa7fec8ac3 /bfd
parentf12a02c018093a098f27099297903362c47ca150 (diff)
downloadgdb-3471d59d313d799d8c4a281114a9a12f98337b03.zip
gdb-3471d59d313d799d8c4a281114a9a12f98337b03.tar.gz
gdb-3471d59d313d799d8c4a281114a9a12f98337b03.tar.bz2
* elf.c (bfd_elf_get_str_section): Fix memory leak caused by
corrupt string table.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/elf.c6
2 files changed, 10 insertions, 1 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 75bc0b6..5539be2 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2008-05-01 Cary Coutant <ccoutant@google.com>
+
+ * elf.c (bfd_elf_get_str_section): Fix memory leak caused by
+ corrupt string table.
+
2008-05-01 Joel Brobecker <brobecker@adacore.com>
* cache.c (cache_bread_1): Renames cache_bread.
diff --git a/bfd/elf.c b/bfd/elf.c
index 2f1ec37..1a32d42 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';