readelf: Save and dump the original section header values
Improves error handling and fixes a buffer overflow in binutils' readelf tool.
This patch refactors parts of binutils’ readelf.c to improve error reporting for malloc failures and fix a potential buffer overflow in orig_section_headers. It simplifies warning messages, removes unused parameters, and adjusts memory allocation and validation logic, particularly when probing ELF headers or handling relr dynamic tags.
In Details
Refactors readelf.c to address two main issues: 1) improving error reporting for malloc failures in save_original_section_header_values to use xmalloc and simplify messages, and 2) fixing a potential buffer overflow in orig_section_headers. The overflow could occur if memory allocation fails during probing, leading to incorrect access when free_filedata is called. The changes also remove unused function parameters and simplify calls to validate_section_info.
- readelf
- A utility that displays information about ELF (Executable and Linkable Format) files, part of the GNU Binutils package.
- section header
- A data structure within an ELF file that describes a section of the file, such as code, data, or symbol tables.
- POT file
- Portable Object Template file. A template file used in software internationalization containing strings to be translated.
- malloc
- A standard C library function that allocates a block of memory on the heap.
- xmalloc
- A variant of
mallocthat typically includes error checking and exits the program if memory allocation fails. - buffer overflow
- A condition where a program writes data beyond the allocated buffer, potentially corrupting adjacent memory and leading to crashes or security vulnerabilities.
- relr dynamic tags
- Refers to dynamic linking information related to relocation entries, specifically the 'relr' (relative relocations) format which is more compact than standard relocation entries.
- ELF header
- The main header of an ELF file, containing general information about the file format and its contents.