diff options
author | Alan Modra <amodra@gmail.com> | 2022-02-09 22:24:44 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-02-09 22:28:14 +1030 |
commit | 2969c3b37b228c34566e7fee63ee2395a1c227ad (patch) | |
tree | 5f60ef5201eddf5c9d614674452cb5a739386ebb /binutils/readelf.c | |
parent | c9fecd62838e481d9902a7fba42a6928370c9b10 (diff) | |
download | gdb-2969c3b37b228c34566e7fee63ee2395a1c227ad.zip gdb-2969c3b37b228c34566e7fee63ee2395a1c227ad.tar.gz gdb-2969c3b37b228c34566e7fee63ee2395a1c227ad.tar.bz2 |
PR28763, SIGSEGV during processing of program headers via readelf
PR 28763
* readelf.c (process_file_header): Discard any cached program
headers if there is an extension field for e_phnum in first
section header.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r-- | binutils/readelf.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c index e56e9b5..b208db5 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -5631,10 +5631,7 @@ process_file_header (Filedata * filedata) if (filedata->section_headers != NULL && header->e_phnum == PN_XNUM && filedata->section_headers[0].sh_info != 0) - { - header->e_phnum = filedata->section_headers[0].sh_info; - printf (" (%u)", header->e_phnum); - } + printf (" (%u)", filedata->section_headers[0].sh_info); putc ('\n', stdout); printf (_(" Size of section headers: %u (bytes)\n"), header->e_shentsize); @@ -5667,7 +5664,12 @@ process_file_header (Filedata * filedata) { if (header->e_phnum == PN_XNUM && filedata->section_headers[0].sh_info != 0) - header->e_phnum = filedata->section_headers[0].sh_info; + { + /* Throw away any cached read of PN_XNUM headers. */ + free (filedata->program_headers); + filedata->program_headers = NULL; + header->e_phnum = filedata->section_headers[0].sh_info; + } if (header->e_shnum == SHN_UNDEF) header->e_shnum = filedata->section_headers[0].sh_size; if (header->e_shstrndx == (SHN_XINDEX & 0xffff)) |