summaryrefslogtreecommitdiffstats
path: root/src/readelf.c
Commit message (Collapse)AuthorAgeFilesLines
* readelf: Extend -z to dumping hex and string sections (-x and -p).upstream/mjw/compress2Mark Wielaard2015-11-021-9/+45
| | | | | | | | -z, --decompress Show compression information for compressed sections (when used with -S); decompress section before dumping data (when used with -p or -x) Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add -z,--decompress option.Mark Wielaard2015-10-291-3/+63
| | | | | | | -z, --decompress Show compression information for compressed sections (when used with -S). Signed-off-by: Mark Wielaard <[email protected]>
* Trust AC_SYS_LARGEFILE to provide large file supportJosh Stone2015-10-091-3/+3
| | | | | | | | | | | | | | | AC_SYS_LARGEFILE defines _FILE_OFFSET_BITS in config.h if needed for LFS, and this automatically maps things like open to open64. But quite a few places used explicit 64-bit names, which won't work on platforms like FreeBSD where off_t is always 64-bit and there are no foo64 names. It's better to just trust that AC_SYS_LARGEFILE is doing it correctly. But we can verify this too, as some file could easily forget to include config.h. The new tests/run-lfs-symbols.sh checks all build targets against lfs-symbols (taken from lintian) to make sure everything was implicitly mapped to 64-bit variants when _FILE_OFFSET_BITS is set. Signed-off-by: Josh Stone <[email protected]>
* Do without union of variable length arrays.Chih-Hung Hsieh2015-10-071-9/+17
| | | | | | | | | | | | | | Prepare to compile with clang. A union like { T32 a32[n]; T64 a64[n]; } u; is expanded to size_t nbytes = n * MAX(sizeof(T32), sizeof(T64)); void *data = malloc(nbytes); T32 (*a32)[n] = data; T64 (*a64)[n] = data; Signed-off-by: Chih-Hung Hsieh <[email protected]>
* Initialize variable before use.Chih-Hung Hsieh2015-09-101-1/+2
| | | | | | Some compiler does not know that error function never returns. Signed-off-by: Chih-Hung Hsieh <[email protected]>
* Replace printf %Z length modifier with %z.Chih-Hung Hsieh2015-09-071-21/+21
| | | | | | | | %Z is a GNU extension predating the ISO C99 %z modifier supported by libc5 and no longer recommended. Signed-off-by: Chih-Hung Hsieh <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* readelf: handle_core_item large right shift triggers undefined behaviour.Mark Wielaard2015-09-031-2/+10
| | | | | | | | | | | | | | | | | | | | | | The problem is this: int n = ffs (w); w >>= n; The intent is to shift away up to (and including) the first least significant bit in w. But w is an unsigned int, so 32 bits. And the least significant bit could be bit 32 (ffs counts from 1). Unfortunately a right shift equal to (or larger than) the length in bits of the left hand operand is undefined behaviour. We expect w to be zero afterwards. Which would terminate the while loop in the function. But since it is undefined behaviour anything can happen. In this case, what will actually happen is that w is unchanged, causing an infinite loop... gcc -fsanitize=undefined will catch and warn about this when w = 0x80000000 https://bugzilla.redhat.com/show_bug.cgi?id=1259259 Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Make sure phdr2_mem lifetime/scope equals phdr2 pointer.Mark Wielaard2015-06-191-1/+1
| | | | | | | We dont' want GCC to dispose or reuse phdr2_mem stack memory while phdr2 is pointing to it. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Don't leak memory on failure path in handle_gnu_hash.Mark Wielaard2015-06-191-1/+3
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix cie_offset calculation comparison on 32bit.Mark Wielaard2015-04-281-2/+2
| | | | | | | | | gcc -fsanitize=undefined pointed out that on 32bit systems the calculation to match the cie_offset to the cie_id could be undefined because a cie_id could be an unsigned 64bit value while ptrdiff_t is only 32bits. Correct the calculation to use 64bit values. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Check all offsets used in print_gdb_index_section against d_size.Mark Wielaard2015-04-281-2/+13
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Always try to print some debug section information.Mark Wielaard2015-04-281-2/+0
| | | | | | | | Even if we cannot create a proper Dwarf dbg we can still print the information of various debug sections. All all debug print section functions already check first they can access the appropriate data. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add overflow checking to print_gdb_index_section dataend checks.Mark Wielaard2015-04-281-9/+15
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <[email protected]>
* Publish known-dwarf.hPetr Machata2015-03-311-47/+43
| | | | | | | | | | | | | - Make the macro names properly scoped (DWARF_ALL_KNOWN_* and DWARF_ONE_KNOWN_*). - Simplify the calling convention: don't keep track of the comment associated with the enumerator, always use the non-_DESC DWARF_ONE_KNOWN_* callback. - Install known-dwarf.h alongside libdw.h and others. Signed-off-by: Petr Machata <[email protected]>
* readelf: Don't try to read macinfo cus sentinel or beyond.Mark Wielaard2015-01-121-1/+2
| | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810 Reported-by: Alexander Cherepanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add more sanity checks to print_debug_exception_table.Mark Wielaard2015-01-121-4/+14
| | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810 Reported-by: Alexander Cherepanov <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add bounds check before each CFA op that takes an argument.Mark Wielaard2014-12-171-2/+40
| | | | | | | Some CFA ops don't take any arguments, for those it is valid to be at the end of the data block. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Print dwarf_errmsg if dwarf_onesrcline or dwarf_linesrc fails.Mark Wielaard2014-12-171-1/+11
| | | | | | Don't just crash using the NULL result in print_decoded_line_section. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Correct overflow check for length in print_debug_aranges_section.Mark Wielaard2014-12-171-1/+1
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf,libdw: Correct .debug_line overflow check for unit_length.Mark Wielaard2014-12-171-2/+2
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Warn, don't assert, if loclist or rangelist offset is too big.Mark Wielaard2014-12-171-16/+29
| | | | | | | | | We use a couple of bits to keep track of the addr size, dwarf size and warning given for a loclist or rangelist offset. Normally offset won't be that big and will fit in 61-bits easily. But if not, don't assert, but just warn we don't handle such large offsets. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Don't assert when addr_size or ref_size is not 4 or 8 in print_ops.Mark Wielaard2014-12-171-15/+8
| | | | | | Just report invalid data and continue. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add more bounds checks to print_gdb_index_section.Mark Wielaard2014-12-171-3/+5
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Make sure there is enough room for reading .debug_line unit_length.Mark Wielaard2014-12-171-0/+2
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Check there is enough room for the DW_LNE_set_address argumentMark Wielaard2014-12-171-0/+2
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add get_uleb128 and get_sleb128 bounds checking.Mark Wielaard2014-12-171-110/+147
| | | | | | | | | | | Both get_uleb128 and get_sleb128 now take an end pointer to prevent reading too much data. Adjust all callers to provide the end pointer. There are still two exceptions. "Raw" dwarf_getabbrevattr and read_encoded_valued don't have a end pointer associated yet. They will have to be provided in the future. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Check TType base offset and Action table are sane in exception table.Mark Wielaard2014-12-151-2/+9
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Don't print more augmentation characters than there are.Mark Wielaard2014-12-151-3/+4
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Check count fits and doesn't overflow fptr in handle_file_note.Mark Wielaard2014-12-121-2/+6
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Report invalid data if action table doesn't follow call site table.Mark Wielaard2014-12-121-1/+2
| | | | | | Don't assert. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: maximum operations per instruction cannot be zero in .debug_line.Mark Wielaard2014-12-111-0/+8
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: DW_OP_call_ref and DW_OP_GNU_implicit_pointer are invalid for CFA.Mark Wielaard2014-12-111-0/+4
| | | | | | | | | print_cfa_program might call print_ops with zero offset size. We don't need (and don't know) the DWARF offset size in that case. DW_OP_call_ref and DW_OP_GNU_implicit_pointer need to know the offset size because they reference a DIE. But they are invalid when used from CFA. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix overflow check in handle_sysv_hash64.Mark Wielaard2014-12-041-2/+4
| | | | | | | Since all values are 64bit, not 32bit as in other hashes, we need to explicitly check for overflow. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Don't trash destshdr for STT_SECTION in handle_relocs_rel[a].Mark Wielaard2014-12-041-14/+20
| | | | | | We might need the original destshdr for handling other relocations. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Cast Dwarf_Word length to ptrdiff_t for comparison.Mark Wielaard2014-11-271-1/+1
| | | | | | Avoids comparison between signed and unsigned integer expressions warning. Signed-off-by: Mark Wielaard <[email protected]>
* readelf, libdw: Guard against divide by zero line_range in .debug_line.Mark Wielaard2014-11-261-0/+7
| | | | | | | For DW_LNS_const_add_pc and special opcodes don't accept line_range being zero. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Check length for nexthdr overflow in print_debug_aranges_section.Mark Wielaard2014-11-261-1/+1
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: print_attributes (-A) robustify and handle non-gnu attributes.Mark Wielaard2014-11-261-8/+36
| | | | | | | | | | | print_attributes wasn't robust against empty or broken attribute sections. It also only handled GNU attributes. But the arm backend contains some none-GNU attributes. The difference is in how to handle the tag arguments. Adds a new test run-readelf-A.sh for both gnu (ppc32) and non-gnu (arm) attributes. Signed-off-by: Mark Wielaard <[email protected]>
* Use elf_getphdrnum instead of accessing ehdr->e_phnum directly.Mark Wielaard2014-11-261-6/+1
| | | | | | | Using elf_getphdrnum lets us handle ELF files that use more than PN_XNUM phdrs. And guards against some corrupt files. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix sanity check of DW_FORM_block length in print_cfa_programMark Wielaard2014-11-181-1/+1
| | | | | | We were checking the reg nr, not the length of the block. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: When the version chain ends, stop processing the entries.Mark Wielaard2014-11-171-2/+26
| | | | | | | | | | The version definition, auxiliary version, version dependency and needed version sections chain information together through "next" fields. When the "next" field is zero there are no more information entries. Stop processing when we see zero instead of repeatedly processing the same entry (at offset zero from the current one). Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Warn if ptr_size is not 4 or 8 bytes.Mark Wielaard2014-11-171-3/+6
| | | | | | | Just warn and don't call print_cfa_program in that case. Bad things will happen and the result is mostly bogus. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Fix handling of (extended) phnum.Mark Wielaard2014-11-171-1/+6
| | | | | | | | If there is no e_phoff e_phnum cannot be trusted. Extended phnum can only be gotten if we have an actual section table and a shdr for section zero, Extended phnum can be too large to fit in the file (or a size_t). Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Robustify print_cfa_program.Mark Wielaard2014-11-161-0/+10
| | | | | | Check block len before calling print_ops. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Sanity check CIE unit_length and augmentationlen in debug_frame.Mark Wielaard2014-11-141-1/+16
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Check def == NULL before use in handle_versym.Mark Wielaard2014-11-141-1/+4
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf.c (handle_versym): Initialize vername and filename array elements.Mark Wielaard2014-11-081-0/+2
| | | | | | | | We check whether the elements are set before printing their contents, but didn't make sure they were initialized. Reported-by: Hanno Böck <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Sanity check hash section contents before processing.Mark Wielaard2014-11-081-1/+48
| | | | | Reported by: Hanno Böck <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix typo in a check in handle_relocs_relaPetr Machata2014-09-231-1/+1
| | | | | | | | - Testing shdr makes no sense, that pointer was dereferenced several times throughout the section. destshdr on the other hand is not tested at all. Signed-off-by: Petr Machata <[email protected]>
* Rename read_ubyte_unaligned_inc to read_addr_unaligned_incPetr Machata2014-09-121-7/+9
| | | | | | | | | | | | | | - The behavior of this function has been changed to read only address-sized quantities, i.e. the size of 2 is no longer allowed. (Size of 1 never was.) The two outstanding uses, both in readelf.c, which actually do use this call to read address-sized units, were updated, rejecting fields that indicate weird address sizes. - The three related calls, read_sbyte_unaligned_inc, read_ubyte_unaligned and read_sbyte_unaligned were dropped. There are currently no uses for these calls. Signed-off-by: Petr Machata <[email protected]>