[binutils-gdb] readelf info leaks from one object to the next
Alan Modra
amodra@sourceware.org
Fri Jun 11 08:04:48 GMT 2021
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=066f8fbede55e781c6241c445e0940f8368d0ef9
commit 066f8fbede55e781c6241c445e0940f8368d0ef9
Author: Alan Modra <amodra@gmail.com>
Date: Fri Jun 11 12:49:02 2021 +0930
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.
Diff:
---
binutils/ChangeLog | 6 ++++++
binutils/readelf.c | 30 +++++-------------------------
2 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index bd91a3911d2..e84f5d36dec 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+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..
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 52d5302d07b..1456c03a073 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
More information about the Binutils-cvs
mailing list