summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* readelf: Clean up section lists after usage.Mark Wielaard2019-05-142-0/+19
| | | | Signed-off-by: Mark Wielaard <mark@klomp.org>
* lib/color: Fix compilation with uClibcRosen Penev2019-05-052-1/+5
| | | | | | | elfutils passed -Werror and this call errors on uClibc with a mismatching pointer type. Cast to char * to fix. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* libelf: Add n_namesz offset overflow check to gelf_get_note.Mark Wielaard2019-05-042-2/+8
| | | | | | | | | | During fuzzing of the new xlate_notes testcase I noticed that gelf_get_note didn't check whether the n_namesz of a note was too big. This could lead to offset wrapping around. Causing an infinite loop going over all ELF notes. Fix by adding an overflow check before updating offset. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: If xlate can only convert the ELF note header, just do that.Mark Wielaard2019-05-046-5/+283
| | | | | | | | | | | | | | | | | When we started parsing new style ELF_T_NHDR8 notes we added extra checks on alignment and padding. When those failed we would stop converting and just return the rest of the ELF Note unconverted. In the case were we just had enough data for just the ELF Note header and the destionation and source weren't the same we would then accidentially throw away the Note header conversion we just did. Fix that by indicating we did correctly convert just the header. Adds testcase that compares parsing ELF notes with gelf_getnote and parsing the raw data by hand using elf32_xlatetom using just the Note header and ignoring the (raw) note data. Signed-off-by: Mark Wielaard <mark@klomp.org>
* tests: Don't printf a known NULL symname in backtrace-dwarf.c.Mark Wielaard2019-04-302-1/+6
| | | | | | | | | | GCC9 on 32bit systems might warn about '%s' directive argument is null for symname in backtrace-dwarf.c. Just check whether symname is NULL. This is an identical fix for the same issue as found in backtrace.c, but now in backtrace-dwarf.c Signed-off-by: Mark Wielaard <mark@klomp.org>
* tests: Don't printf a known NULL symname.Mark Wielaard2019-04-302-1/+5
| | | | | | | GCC9 on 32bit systems might warn about '%s' directive argument is null for symname in backtrace.c. Just check whether symname is NULL. Signed-off-by: Mark Wielaard <mark@klomp.org>
* unstrip: Robustify gelf_getshdr and gelf_getsymshndx calls.Mark Wielaard2019-04-282-0/+10
| | | | Signed-off-by: Mark Wielaard <mark@klomp.org>
* size: Robustify against gelf_getshdr returning NULL.Mark Wielaard2019-04-282-0/+13
| | | | Signed-off-by: Mark Wielaard <mark@klomp.org>
* nm: Simplify naming of invalid sections, check shdr isn't NULL.Mark Wielaard2019-04-282-8/+11
| | | | | | | | | When shdr is NULL or the sh_name index is invalid, don't try to use it. Just call the section "[invalid section name]". Don't try to be too smart by creating a dynamic invalid name using alloca to simplify memory usage in this exceptional case. Signed-off-by: Mark Wielaard <mark@klomp.org>
* elfcmp: Handle bad sections without crashing.Mark Wielaard2019-04-282-3/+7
| | | | | | | If we cannot get the Shdr of a section then don't try to use or compare them. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libebl: Check ebl is not NULL in ebl_symbol_[binding|type]_name.Mark Wielaard2019-04-283-0/+9
| | | | | | | For STB_GNU_UNIQUE and STT_GNU_IFUNC we need to check the elf of the given ebl. Make sure the ebl given isn't NULL. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure to left shift a unsigned 64bit value in expr_eval.Mark Wielaard2019-04-282-1/+6
| | | | | | | | In frame_unwind.c expr_eval we left shift 1 up to 56 bits. We have to make sure we don't left shift a 32bit signed value (that would be undefined behavior). So shift a 1ULL value instead. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Don't call realloc with zero in cu.c addraranges.Mark Wielaard2019-04-282-2/+9
| | | | | | | | | | | Calling realloc when naranges is zero will result is trying to free aranges. If realloc does free aranges it returns NULL, which means aranges is still assigned. This is likely not a problem, because in most cases aranges will be NULL already. But if it was not and naranges does turn out to be zero after reduction (which would be invalid DWARF) we are left with a dangling pointer. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdw: Remove unused variable initialization in dwarf_siblingof.Mark Wielaard2019-04-282-1/+5
| | | | | | We immediately reassign the value of addr after declaration. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdw: Call check_constant_offset with direct pointers.Mark Wielaard2019-04-282-1/+6
| | | | | | | | In dwarf_getlocation_addr pass the pointers to llbufs and listlens indirectly by passing a pointer to the first array element. Simplify the code by passing the pointers directly. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdw: Reject DW_OP_implicit_value in CFI.Mark Wielaard2019-04-282-0/+7
| | | | | | | | | | When we encounter a DW_OP_implicit_value we call store_implicit_value () which will try to store the value as part of the Dwarf dbg. But if we are examining CFI there will be no Dwarf dbg. And DW_OP_implicit_value should not be part of CFI. So explicitly reject it in store_implicit_value if dbg is NULL. Signed-off-by: Mark Wielaard <mark@klomp.org>
* config: Add git tag --verify to upload-release.sh.Mark Wielaard2019-04-152-0/+5
| | | | | | Add a check to make sure we have to correct (signed) tag. Signed-off-by: Mark Wielaard <mark@klomp.org>
* backends: riscv_cfi.c had a bad BACKEND define.Mark Wielaard2019-04-142-1/+5
| | | | | | | BACKEND should have been defined as riscv_ (not aarch64_). Reported-by: Mao Han <han_mao@c-sky.com> Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Sync elf.h from glibcMao Han2019-04-142-2/+98
| | | | Signed-off-by: Mao Han <han_mao@c-sky.com>
* readelf: Print DW_AT_data_member_location as decimal offset, not hex number.Mark Wielaard2019-04-102-1/+6
| | | | | | | | | | | | | The data_member_location attribute was printed as a hex number, but other constant attributes like bit_offset, byte_size or alignment were printed as decimal numbers. This is confusing. The reason that data_member_location was printed as hex seemed to have been because it could also have been a location description, in which case it might have been of DW_FORM_loclist, for which it makes sense to print as hex offset (between square brackets). Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf: print_debug_macinfo_section, check cus[0] is not the sentinel.Mark Wielaard2019-03-292-3/+8
| | | | | | | | If there are no CUs at all we can not find any CU DIE file. https://sourceware.org/bugzilla/show_bug.cgi?id=24398 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Sanity check partial core file phdrs data read.Mark Wielaard2019-03-272-0/+11
| | | | | | | | | When reading the phdrs data from the core file check if we got everything, or just part of the data. https://sourceware.org/bugzilla/show_bug.cgi?id=24387 Signed-off-by: Mark Wielaard <mark@klomp.org>
* strip: Files with symbols referring to non-existing sections are illformedMark Wielaard2019-03-272-0/+5
| | | | | | | | | | The check added in commit 4540ea98c "strip: Fix check test for SHN_XINDEX symbol" was not complete. The (extended) section index should also exist. If it doesn't exist, mark the file as illformed. https://sourceware.org/bugzilla/show_bug.cgi?id=24385 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Use posix_memalign instead of aligned_alloc.Mark Wielaard2019-03-072-3/+22
| | | | | | | | Older glibc might not have aligned_alloc (it is C11). Use posix_memalign instead. posix_memalign requires the alignment to be a multiple of sizeof (void *). So use malloc for smaller alignments. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libasm: Check return value of gelf_update_ehdr in asm_end.Mark Wielaard2019-03-062-1/+9
| | | | | | | In theory the gelf_update_ehdr call could fail. Immediately report an error in that case. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Fix possible resource leak in elf[32|64]_updatefile.Mark Wielaard2019-03-062-0/+6
| | | | | | | When we cannot allocate enough memory to convert the data in updatemmap we should free the scns before returning an error. Signed-off-by: Mark Wielaard <mark@klomp.org>
* tests: Remove tgkill define from backtrace.cMark Wielaard2019-03-042-1/+4
| | | | | | | | tgkill is never used in the test and it might conflict with newer glibc which might define tgkill themselves (just like gettid): https://sourceware.org/bugzilla/show_bug.cgi?id=6399 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Remove unused __elf_xfctstof.Mark Wielaard2019-02-283-6/+5
| | | | | | | __elf_xfctstof is only used in case the memory size and file size of ELF data structures are different. This is never the case. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Remove unused internal __elf[32|64]_msize functions.Mark Wielaard2019-02-283-12/+7
| | | | | | | | | Those functions were intended for ELF versions where the memory and file sizes of data structures are different. They were never used because libelf depends on the file and memory sizes being equal (otherwise using mmap wouldn't work). Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: There is just one ELF version.Mark Wielaard2019-02-2817-176/+111
| | | | | | | | | | | | | | Remove (partially defined out) code and data structures dealing with multiple ELF versions. There hasn't been a new ELF version in the last 20 years. Simplify the code a bit by just assuming there will only be one version (EV_CURRENT == 1). Simplifies elf_version, gets rid of __libelf_version_initialized. Removes one (or more) array (version) dimension from various tables and accessor functions (__elf_xfctstom, shtype_map, __libelf_data_type, __libelf_type_aligns and __libelf_type_sizes). Signed-off-by: Mark Wielaard <mark@klomp.org>`
* libdwfl: Initialize notes early in intuit_kernel_bounds.Mark Wielaard2019-02-282-5/+8
| | | | | | | | We fake initialization of notes with an empty asm statement. But it is simpler and less confusing to just initialize notes just before the fopen. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Handle zero size decompressed data.Mark Wielaard2019-02-192-13/+28
| | | | | | | | | | | | | | This is a corner case that will most likely never occur in practice, but we have several testcases that compress and decompress zero sized data. In that case during decompression we might malloc a buffer of size zero. It is allowed for malloc to return NULL in that case. But we do need a non-NULL buffer to return and set as result. So make sure to always at least allocate one byte. Also make sure that we don't allocate a zero sized conversion buffer for the data. https://sourceware.org/bugzilla/show_bug.cgi?id=24000 Signed-off-by: Mark Wielaard <mark@klomp.org>
* s390: elflint should check if _GLOBAL_OFFSET_TABLE_ points to .got.elfutils-0.176Mark Wielaard2019-02-153-0/+44
| | | | | | | | | | The _GLOBAL_OFFSET_TABLE_ symbol might point to the DT_PLTGOT, which is in the .got section, even if the symbol itself is associated with the .got.plt section. See https://sourceware.org/ml/binutils/2018-07/msg00200.html Signed-off-by: Mark Wielaard <mark@klomp.org>
* Prepare for 0.176Mark Wielaard2019-02-1412-691/+804
| | | | | | | | | Set version to 0.176. Update NEWS and elfutils.spec.in. Update GPG-KEY. Regenerate po/*.po files. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Make sure ar_size is terminated when reading ar long names.Mark Wielaard2019-02-142-4/+23
| | | | | | | | | | The ar_size is given as a fixed size decimal string, right padded with spaces. Make sure we read it properly even if there is no terminating space. Also sanity check len early if we can. https://sourceware.org/bugzilla/show_bug.cgi?id=24085 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdw: Check there is enough space for CU 64bit length, version and type.Mark Wielaard2019-02-012-3/+20
| | | | | | | | | | | We only checked we could read the initial length and after knowing the version and type whether the unit header was the right size. Also check there are at least enough bytes to read the 64bit length, version and unit type bytes. https://sourceware.org/bugzilla/show_bug.cgi?id=24140 Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf: Check there is enough data to read DWARF line opcodes arguments.Mark Wielaard2019-02-011-4/+14
| | | | | | | | | | | When reading the debug_line opcode arguments we have to make sure there is enough data to read the arguments (if there are any(. The similar code in dwarf_getsrclines already had these checks. https://sourceware.org/bugzilla/show_bug.cgi?id=24116 Signed-off-by: Mark Wielaard <mark@klomp.org>
* configure: Add new --enable-install-elfh option.Mark Wielaard2019-01-316-4/+41
| | | | | | | | | | | | | | We explicitly test (with system-elf-libelf) that our include headers work with the system elf.h header. But it might be helpful to install the elf.h file for a private install. Our elf.h header really is just a copy of the latest glibc elf.h. But it might be newer and include more constants than the system installed elf.h. Add a new configure option --enable-install-elfh to install elf.h. But warn when it is enabled for the default /usr or /usr/local prefix because it might clash with the glibc/system elf.h header in that case. Signed-off-by: Mark Wielaard <mark@klomp.org>
* tests: Remove assert (errno == 0) from tests.Mark Wielaard2019-01-314-17/+10
| | | | | | | When a function fails it might set errno. But it isn't a guarantee that if a function succeeds that it sets errno to zero. Signed-off-by: Mark Wielaard <mark@klomp.org>
* tests: parse inode in /proc/pid/maps/correctly in run-backtrace-data.shYonghong Song2019-01-312-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | The backtrace-data.c parsed the inode in /proc/pid/maps with format "%*x". This caused failure if inode is big. For example, 7f269223d000-7f269226b000 r-xp 00000000 00:50 10224326387095067468 /home/... The error likes below: -bash-4.4$ cat run-backtrace-data.sh.log backtrace-data: /home/engshare/elfutils/0.174/src/elfutils-0.174/tests/backtrace-data.c:110: maps_lookup: Assertion `errno == 0' failed. /home/engshare/elfutils/0.174/src/elfutils-0.174/tests/test-subr.sh: line 84: 3123578 Aborted (core dumped) LD_LIBRARY_PATH="${built_library_path}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" $VALGRIND_CMD "$@" data: no main -bash-4.4$ The reason is errno is ERANGE. Fix the test with inode format string "%*u" as inode here is presented as decimal numbers. Suggested-by: Mark Wielaard <mark@klomp.org> Signed-off-by: Yonghong Song <yhs@fb.com>
* libebl: Check GNU property note data padding fits inside note.Mark Wielaard2019-01-302-8/+14
| | | | | | | | | The GNU property note data is padded. Make sure the extra padding still fits in the note description. https://sourceware.org/bugzilla/show_bug.cgi?id=24075 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: parse inode in /proc/pid/maps correctlyYonghong Song2019-01-292-1/+6
| | | | | | | | | | | | | | | | | | | The inode number in /proc/pid/maps is displayed as "unsigned long" type. In one of our x64 system, we have inode number exceeding valid "long" type range, which caused the following test failure: FAIL: dwfl-bug-fd-leak FAIL: run-backtrace-dwarf.sh FAIL: vdsosyms The offending map entry: 7f269246b000-7f269246c000 rw-p 0002e000 00:50 10224326387095067468 /home/... This patch changed sscanf inode number type from PRIi64 to PRIu64 and fixed the problem. Signed-off-by: Yonghong Song <yhs@fb.com>
* tests: Use separate files for strip outputsUlf Hermann2019-01-243-28/+51
| | | | | | | | | | This way we can verify that strip actually created all of them. Also, check that strip, unstrip, elflint actually succeed in run-strip-test-many.sh. This exposed the fact that the generated testfile in run-strip-test-many.sh is considered as illformed by strip -g. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* strip: Fix check test for SHN_XINDEX symbol.Mark Wielaard2019-01-244-10/+39
| | | | | | | | | | | | | The check for whether a symbol used the extended section table was wrong causing the run-strip-test-many.sh testcase to declare the testfile was an illformed file. Fixing this exposed a strict elfutils check for the '.shstrtab' section having this exact name and a SHT_STRTAB type. This might be a little too strict, but easily worked around by changing the name of the "old" shstrtab section in the addsections program. Signed-off-by: Mark Wielaard <mark@klomp.org>
* readelf: Don't go past end of line data reading unknown opcode parameters.Mark Wielaard2019-01-222-1/+7
| | | | | | https://sourceware.org/bugzilla/show_bug.cgi?id=24116 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdw: Check terminating NUL byte in dwarf_getsrclines for dir/file table.Mark Wielaard2019-01-224-5/+24
| | | | | | | | | | | | | For DWARF version < 5 the .debug_line directory and file tables consist of a terminating NUL byte after all strings. The code used to just skip this without checking it actually existed. This could case a spurious read past the end of data. Fix the same issue in readelf. https://sourceware.org/bugzilla/show_bug.cgi?id=24102 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Sanity check partial core file dyn data read.Mark Wielaard2019-01-222-0/+11
| | | | | | | | | When reading the dyn data from the core file check if we got everything, or just part of the data. https://sourceware.org/bugzilla/show_bug.cgi?id=24103 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libebl: Check NT_PLATFORM core notes contain a zero terminated string.Mark Wielaard2019-01-167-26/+42
| | | | | | | | | | Most strings in core notes are fixed size. But NT_PLATFORM contains just a variable length string. Check that it is actually zero terminated before passing to readelf to print. https://sourceware.org/bugzilla/show_bug.cgi?id=24089 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libelf: Correct overflow check in note_xlate.Mark Wielaard2019-01-162-2/+7
| | | | | | | | | | We want to make sure the note_len doesn't overflow and becomes shorter than the note header. But the namesz and descsz checks got the note header size wrong). Replace the wrong constant (8) with a sizeof cvt_Nhdr (12). https://sourceware.org/bugzilla/show_bug.cgi?id=24084 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libebl: Check GNU property note pr_datasz fits inside note description.Mark Wielaard2019-01-162-0/+11
| | | | | | | | | Before printing the data values, make sure pr_datasz doesn't go beyond the end of the note description data. https://sourceware.org/bugzilla/show_bug.cgi?id=24075 Signed-off-by: Mark Wielaard <mark@klomp.org>