aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-06-11 12:49:02 +0930
committerAlan Modra <amodra@gmail.com>2021-06-11 14:23:18 +0930
commit066f8fbede55e781c6241c445e0940f8368d0ef9 (patch)
treee2141dd7c4da7a99e434bde0d122ada74d99487f /binutils
parent4de91c10cdd9f5818599578667802320df305d72 (diff)
downloadgdb-066f8fbede55e781c6241c445e0940f8368d0ef9.zip
gdb-066f8fbede55e781c6241c445e0940f8368d0ef9.tar.gz
gdb-066f8fbede55e781c6241c445e0940f8368d0ef9.tar.bz2
readelf info leaks from one object to the next
A number of filedata entries were not cleared. Make sure they are all cleared out, except the ones needed for archive handling. * readelf.c (struct filedata): Move archive_file_offset and archive_file_size earlier. (free_filedata): Clear using memset.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog6
-rw-r--r--binutils/readelf.c30
2 files changed, 11 insertions, 25 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index bd91a39..e84f5d3 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,5 +1,11 @@
2021-06-11 Alan Modra <amodra@gmail.com>
+ * readelf.c (struct filedata): Move archive_file_offset and
+ archive_file_size earlier.
+ (free_filedata): Clear using memset.
+
+2021-06-11 Alan Modra <amodra@gmail.com>
+
* readelf.c (GET_ELF_SYMBOLS): Delete. Replace with..
(get_elf_symbols): ..this new function throughout.
(get_32bit_section_headers): Don't free section_headers.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 52d5302..1456c03 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -263,12 +263,13 @@ typedef struct filedata
FILE * handle;
bfd_size_type file_size;
Elf_Internal_Ehdr file_header;
+ unsigned long archive_file_offset;
+ unsigned long archive_file_size;
+ /* Everything below this point is cleared out by free_filedata. */
Elf_Internal_Shdr * section_headers;
Elf_Internal_Phdr * program_headers;
char * string_table;
unsigned long string_table_length;
- unsigned long archive_file_offset;
- unsigned long archive_file_size;
unsigned long dynamic_addr;
bfd_size_type dynamic_size;
size_t dynamic_nent;
@@ -21191,35 +21192,14 @@ static void
free_filedata (Filedata *filedata)
{
free (filedata->program_interpreter);
- filedata->program_interpreter = NULL;
-
free (filedata->program_headers);
- filedata->program_headers = NULL;
-
free (filedata->section_headers);
- filedata->section_headers = NULL;
-
free (filedata->string_table);
- filedata->string_table = NULL;
- filedata->string_table_length = 0;
-
free (filedata->dump.dump_sects);
- filedata->dump.dump_sects = NULL;
- filedata->dump.num_dump_sects = 0;
-
free (filedata->dynamic_strings);
- filedata->dynamic_strings = NULL;
- filedata->dynamic_strings_length = 0;
-
free (filedata->dynamic_symbols);
- filedata->dynamic_symbols = NULL;
- filedata->num_dynamic_syms = 0;
-
free (filedata->dynamic_syminfo);
- filedata->dynamic_syminfo = NULL;
-
free (filedata->dynamic_section);
- filedata->dynamic_section = NULL;
while (filedata->symtab_shndx_list != NULL)
{
@@ -21229,7 +21209,6 @@ free_filedata (Filedata *filedata)
}
free (filedata->section_headers_groups);
- filedata->section_headers_groups = NULL;
if (filedata->section_groups)
{
@@ -21247,8 +21226,9 @@ free_filedata (Filedata *filedata)
}
free (filedata->section_groups);
- filedata->section_groups = NULL;
}
+ memset (&filedata->section_headers, 0,
+ sizeof (Filedata) - offsetof (Filedata, section_headers));
}
static void