This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] readelf: Free dynamic_section after use


Hi,

 I have noticed on the MIPS platform `readelf -A' can crash if run over a 
mixture of files that do and do not have the dynamic section respectively.  
I have tracked it down to the dynamic_section global variable not being 
cleaned up after use.  As a result when the next file is processed and it 
happens not to have the dynamic section process_mips_specific() proceeds 
anyway and crashes as it tries to interpret stale data from the dynamic 
section previously retrieved.

 Here's an obvious fix.  Regression-tested with the mips-linux-gnu target.

2011-01-19  Maciej W. Rozycki  <macro@codesourcery.com>

	binutils/
	* readelf.c (process_object): Free dynamic_section after use.

 OK to apply?

  Maciej

binutils-readelf-dynamic-section.diff
Index: binutils-fsf-trunk-quilt/binutils/readelf.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/binutils/readelf.c	2011-01-17 22:33:15.000000000 +0000
+++ binutils-fsf-trunk-quilt/binutils/readelf.c	2011-01-17 22:47:01.000000000 +0000
@@ -12416,6 +12416,12 @@ process_object (char * file_name, FILE *
       dynamic_syminfo = NULL;
     }
 
+  if (dynamic_section)
+    {
+      free (dynamic_section);
+      dynamic_section = NULL;
+    }
+
   if (section_headers_groups)
     {
       free (section_headers_groups);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]