readelf: Save and dump the original section header values

validate_section_info clears the garbage values in the section header
to avoid crash later.  Save and dump the original section header values
to make the garbage values in the section header visible when dumping
section headers.

Note: orig_section_headers, instead of sane_section_headers, is added to
filedata since filedata->section_headers is used in many places.  Replace
filedata->section_headers with filedata->sane_section_headers requires
a much bigger change.

	* readelf.c (filedata): Add orig_section_headers.
	(save_original_section_header_values): New.
	(validate_section_info): Add a pointer to the original section
	header and call save_original_section_header_values to save the
	original section header values before clearing the section header
	fields.
	(get_32bit_section_headers): Allocate the original section header
	buffer.  Pass the original section header pointer to
	validate_section_info.
	(get_64bit_section_headers): Likewise.
	(process_section_headers): Dump the original section header
	values if they exist.
	(process_relocs): Pass a dummy original section pointer to
	validate_section_info.
	(free_filedata): Free filedata->orig_section_headers.
	* testsuite/binutils-all/corrupt-1.elf.bz2: New file.
	* testsuite/binutils-all/corrupt-1.r: Likewise.
	* testsuite/binutils-all/readelf.exp: Run corrupt-1.elf test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 files changed