readelf: Don't dump GOT section after seeing error
Fixes readelf to stop dumping the GOT section if it encounters errors while parsing the input file.
This patch for readelf prevents it from attempting to dump the GOT (Global Offset Table) section if it has already encountered errors during file parsing. This addresses an issue where readelf would continue processing and potentially produce corrupted output or further errors after detecting problems like invalid section sizes or an excessive number of program headers. A new flag seen_error is introduced to track errors.
- proposer
Submits a patch to prevent readelf from dumping the GOT section after encountering errors, improving error handling.
“Don't dump GOT section contents after seeing errors in input: readelf: Error: Section 10 has invalid sh_entsize of 0 readelf: Error: (Using the expected size of 18 for the rest of this dump) readelf: Error: Too many program headers - 0x3030 - the file is not that big”
In Details
The readelf utility, part of binutils, is being modified to improve its error handling. Specifically, when readelf encounters critical errors during the parsing of an ELF file (e.g., incorrect section headers, malformed program headers), it should now gracefully stop attempting to dump certain sections, like the GOT, rather than proceeding and potentially producing misleading or further erroneous output. This change introduces a simple error-tracking mechanism within the ELF parsing functions.
- readelf
- A utility that displays information about ELF (Executable and Linkable Format) files.
- GOT
- Global Offset Table. A table used by position-independent code to store addresses of global variables and functions.
- ELF
- Executable and Linkable Format. A standard file format for object files, executables, shared libraries, and core dumps on Unix-like systems.
- sh_entsize
- Section header entry size. A field in the ELF section header that specifies the size of each entry in a section, applicable to sections like symbol tables or string tables.
- program headers
- Structures in an ELF file that describe how the operating system should load the program into memory.