binutils/binutils-readelf-corrupt-program-headers.patch

30 lines
1.3 KiB
Diff

diff -rup binutils.orig/binutils/readelf.c binutils-2.37/binutils/readelf.c
--- binutils.orig/binutils/readelf.c 2022-02-10 10:10:21.508156583 +0000
+++ binutils-2.37/binutils/readelf.c 2022-02-10 10:13:36.486511842 +0000
@@ -5457,10 +5457,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);
@@ -5493,7 +5490,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))