PR25046, readelf "Reading xxx bytes extends past end of file for dynamic section"

Message ID 20190930045134.GB20197@bubble.grove.modra.org
State New
Headers show
Series
  • PR25046, readelf "Reading xxx bytes extends past end of file for dynamic section"
Related show

Commit Message

Alan Modra Sept. 30, 2019, 4:51 a.m.
process_object does
  if (process_program_headers (filedata))
    process_dynamic_section (filedata);
but process_program_headers can return true before clearing globals
used by process_dynamic_section, leaving stale data from a previous
file.

	PR 25046
	* readelf.c (process_program_headers): Clear dynamic_addr and
	dynamic_size earlier.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/binutils/readelf.c b/binutils/readelf.c
index cc168163b2..0962877ad8 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -5101,6 +5101,9 @@  process_program_headers (Filedata * filedata)
   unsigned int i;
   Elf_Internal_Phdr * previous_load = NULL;
 
+  dynamic_addr = 0;
+  dynamic_size = 0;
+
   if (filedata->file_header.e_phnum == 0)
     {
       /* PR binutils/12467.  */
@@ -5151,9 +5154,6 @@  process_program_headers (Filedata * filedata)
 	}
     }
 
-  dynamic_addr = 0;
-  dynamic_size = 0;
-
   for (i = 0, segment = filedata->program_headers;
        i < filedata->file_header.e_phnum;
        i++, segment++)