summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* libdwfl: Don't stack allocate alternate_name in dwfl_linux_kernel_find_elf.Mark Wielaard2015-05-272-1/+13
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Minimize stack usage in dwfl_linux_kernel_report_offline.Mark Wielaard2015-05-272-8/+22
| | | | | | | | Don't stack allocate module name. Also fixes a latent bug (if the module file didn't have a suffix - which is very unlikely) and an inefficiency. We only need to substitue chars up to the suffix. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Fix possibly unbounded stack usage in __libdw_intern_expression.Mark Wielaard2015-05-272-15/+36
| | | | | | | Create a stack allocated array to hold locs. Allocate locs bigger than the array with malloc and free them when done. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Fix unbounded stack usage in find_prelink_address_sync.Mark Wielaard2015-05-272-19/+47
| | | | | | Allocate phdr and shdr unions with malloc, not alloca. Free after use. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Fix possible unbounded stack usage in cache_sections.Mark Wielaard2015-05-272-9/+33
| | | | | | | For modules with lots of sections cache_sections could blow up the stack theoretically. Don't use alloca, but use malloc with explicit free. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libebl: Don't blow up stack when processing large NT_GNU_ABI_TAG.Mark Wielaard2015-05-272-2/+22
| | | | | | | Normally an NT_GNU_ABI_TAG is large, just 4 words (16 bytes). Only use stack allocated conversion buf for small (max 16 words) notes. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libebl: Use static number for array stack allocation in openbackend.Mark Wielaard2015-05-272-2/+13
| | | | | | | | | Help the compiler see we stack allocate a small array. Add assert to check no machine prefix is ever larger than 16. Current maximum number is 7. This prevents gcc warning about possible unbounded stack usage with -Wstack-usage. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: Fix possible unbounded stack usage in updatefile.Mark Wielaard2015-05-272-3/+26
| | | | | | | Allocate shdr_data and scns with malloc, not alloca. Free after writing section headers. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: Fix possible unbounded stack usage in updatemmap.Mark Wielaard2015-05-272-8/+28
| | | | | | | Allocate temporary shdr storage with malloc, not alloca. Free after writing section headers. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: Fix possible unbounded stack usage in elf_getarsym.Mark Wielaard2015-05-272-2/+17
| | | | | | | The number of entries in the index can be large, don't use alloca to read in temporary data, use malloc (and free after out). Signed-off-by: Mark Wielaard <mjw@redhat.com>
* addr2line: Set scopes to NULL after free in handle_address.Mark Wielaard2015-05-272-0/+5
| | | | | | | If dwarf_getscopes_die () fails then scopes might not be reset and we could cause a double free. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* addr2line: Add --pretty-print option to show all information on one line.Mark Wielaard2015-05-276-11/+81
| | | | | | | | | | | | | | | | | | This adds an option --pretty-print to eu-addr2line to show all information on one line and all inlines on a line of their own. This mimics the same option from binutils addr2line, but without the short option variant -p. Since we already use -p to select the process. Example output: eu-addr2line --pretty-print -s -i -f -C -p$(pidof firefox) 0x00007f368c6f8915 mozilla::ReentrantMonitor::Wait(unsigned int) at ReentrantMonitor.h:92 (inlined by) mozilla::ReentrantMonitorAutoEnter::Wait(unsigned int) at ReentrantMonitor.h:190 A couple of tests were added to check the output matches that of binutils addr2line. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* addr2line: Add demangler support.Mark Wielaard2015-05-277-7/+136
| | | | | | | Makes the -C, --demangle option visible and implements it (ignoring the demangle style argument). Adds a new test with sample output. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* addr2line: Add -a, --address. Print address before for each entry.Mark Wielaard2015-05-276-1/+140
| | | | | | Adds test cases with sample output. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* addr2line: Always parse addresses as hex numbers.Mark Wielaard2015-05-275-3/+15
| | | | | | | | We would sometimes interpret input addresses as decimal or octal. That could be confusing and isn't what binutils addr2line does. Be consistent and always treat input addresses as hex. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* addr2line: Split options in input and output format groups.Mark Wielaard2015-05-272-3/+10
| | | | | | | This makes it clear that -j, --section=NAME is about how input is treated, not how the output is formatted. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: Use posix_fallocate instead of ftruncate to extend ELF file.Mark Wielaard2015-05-272-3/+18
| | | | | | | | | | | | | | | | | | | This fixes an obscure SIGBUS error when using ELF_C_WRITE_MMAP on an ELF file that needs extending when the underlying file system is (nearly) full. Use posix_fallocate to make sure the file content is really there. Using ftruncate might mean the file is extended, but space isn't allocated yet. This might cause a SIGBUS once we write into the mmapped space and the disk is full. Using fallocate might fail on some file systems. posix_fallocate is required to extend the file and allocate enough space even if the underlying filesystem would normally return EOPNOTSUPP or the kernel doesn't implement the fallocate syscall. Also posix_fallocate has been in glibc since 2.1.94, while support for fallocate was only added in 2.10 and kernel 2.6.23. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* configure: Add --enable-sanitize-undefined.Mark Wielaard2015-05-273-2/+26
| | | | | | | | | | | | Now that we are -fsanitize=undefined clean make sure we keep it that way. We do have to disable alignment checking. Because we might explicitly use unaligned accesses (see ALLOW_UNALIGNED). Rename DISTCHECK_CONFIGURE_FLAGS to AM_DISTCHECK_CONFIGURE_FLAGS, so the user can override. And add --enable-sanitize-undefined. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: If e_phnum is zero then set e_phoff also to zero.Mark Wielaard2015-05-182-0/+13
| | | | | | | | | | If phnum is zero make sure e_phoff is also zero and not some random value. That would cause trouble in update_file. This could happen when ELF_F_LAYOUT is set and the user copied over a ehdr from a bogus ELF file where the phdrs are unreadable. In that case trying to write out the new ELF image would crash trying to follow the bogus e_phdr value. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* strip: Harden against bogus input files. Don't leak tmp debug file on error.Mark Wielaard2015-05-182-77/+204
| | | | | | | | | | There were various places where a bogus/unexpected input file would cause eu-strip to crash. Also on an unexpected error eu-strip would leak the temp debug file it was writing. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c34 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: More checking of valid sh_addralign values.Mark Wielaard2015-05-183-0/+26
| | | | | | | | | | | | | | | | | | | | There were two issues with bogus sh_addralign values. First we would only check the individual Elf_Data d_align values were powerof2. But not the actual shdr addralign value. This would cause an issue if the shdr addralign was bigger than all of the individual d_align values. Then we could write out a bogus (! powerof2) shdr addralign value for the sections. Secondly when reading in the Elf_Data we would set the d_align value to the value of the shdr addralign value. But we would not check it was valid at all. In practice there are ELF files with incorrect sh_addralign values (they are a powerof2, but aren't aligned to the ELF image offset). We would try to fix that up in elf_update by adding extra padding. But this could bloat the ELF image a lot for large alignment values. So for too large alignments that are bigger than the offset in the ELF file clamp them to the offset value. This could lead us to reject to write out the data again when the offset was not a powerof2. But this will only happen for aligment values bigger than 64. Which are uncommon in practice. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libelf: Make sure shdrs are valid before storing extended phnum in newphdr.Mark Wielaard2015-05-182-1/+17
| | | | | | | | | Creating phdr with more than PN_XNUM phnum requires a valid section zero shdr to store the extended value. Make sure the shdrs are valid. Also fix the error when count was too big to store by setting ELF_E_INVALID_INDEX before failing. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* dwarf_begin_elf: new error for compression failureJonathan Lebon2015-05-134-61/+97
| | | | | | | | | | | In order to provide better feedback to users, a distinction is made between finding no dwarf info (E_NO_DWARF) and finding dwarf info but which is compressed and failed to decompress (E_COMPRESSED_ERROR). This can occur for example if elfutils was built without zlib support, or if the compressed section is invalid. Signed-off-by: Jonathan Lebon <jlebon@redhat.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* dwarf_begin_elf: decouple section searching from readingJonathan Lebon2015-05-132-31/+36
| | | | | | | | | | | To help legibility, we separate the section name matching from the actual section reading. This also allows us to remove duplicate code in cases of sections appearing twice or empty section data. There are no changes in functionality. The indentation will be fixed in the next commit, in the interest of keeping this commit easier to read. Signed-off-by: Jonathan Lebon <jlebon@redhat.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Always call gelf_fsize with EV_CURRENT as argument.Mark Wielaard2015-05-135-14/+18
| | | | | | | | | | Don't trust the elf version given by the file. It could be completely bogus. In which case gelf_fsize just returns zero. Which could cause divide by zero errors. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c34 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Only intern CU when not EOF marker and cuoff points to a DIE.Mark Wielaard2015-05-122-40/+49
| | | | | | | | | | | | | We need to check the cuoff points to a real Dwarf_Die before trying to intern the cu with tsearch. Otherwise bogus keys might end up in the search tree with NULL cus. That will cause crashes in compare_cukey during next insertion or deletion of cus. We also don't want to insert the EOF marker and unconditionally tdestroy the lazy_cu_root. The EOF could be caused by bad DWARF from a bogus agranges entry. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c30 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Check gnu_hash has enough data and bitmask_words is not zero.Mark Wielaard2015-05-122-7/+22
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c31 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Add sanity checks to check_attributes.Mark Wielaard2015-05-122-2/+6
| | | | | | | | | | This is similar to commit 9644aa for readelf print_attributes. Bail out when the vendor name isn't terminated and add overflow check for subsection_len. Note that readelf does handle non-gnu attributes, while elflint doesn't. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Use Use Elf64_Word for shdr->sh_info cnt.Mark Wielaard2015-05-122-2/+8
| | | | | | | On 32bit using int might overflow. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c31 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* elflint: Stop checking section when 2nd hash function shift too big.Mark Wielaard2015-05-122-2/+10
| | | | | | Nothing good comes from trying to continue with a bogus hash function. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c31
* libdw: Detect line number overflow in dwarf_getsrclines on 32bit.Mark Wielaard2015-05-122-1/+7
| | | | | | | | | | We do check whether the values we store for the line fit our data representation in add_new_line, but on 32bit systems we would fail to notice line overflowing. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c32 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* nm: Handle dwarf_linesrc returning NULL.Mark Wielaard2015-05-122-4/+7
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#32 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: dwarf_getaranges check there is enough data before reading.Mark Wielaard2015-05-122-2/+19
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c30 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Bounds check Dwarf_Fileinfo file number in dwfl_lineinfo.Mark Wielaard2015-05-122-1/+11
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c30 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Make dwfl_error.c C99-kosher.Roland McGrath2015-05-062-4/+24
| | | | Signed-off-by: Roland McGrath <roland@hack.frob.com>
* libelf: Make sure version xlate dest buffer is fully defined.Mark Wielaard2015-05-062-1/+16
| | | | | | | | | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c16 contains an example of usage of undefined memory when version section data needs to be translated, but the version xlate functions detect they cannot fully transform the section data. To make sure the dest buffer data is completely defined this patch makes sure all data is moved from src to dest first. This is somewhat inefficient since normally all data will be fully converted. But the translation functions have no way to indicate only partial data was converted. Reported-by: Alexander Cherepanov <cherepan@mccme.ru> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Replace assert_perror with assertMax Filippov2015-05-055-20/+28
| | | | | | | assert_perror is a GNU extension, it's not provided by uClibc and it's only used in tests. Replace it with assert. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
* Replace futimes with futimens.Max Filippov2015-05-053-13/+21
| | | | | | | | futimes is not standard function, and it's not available in uClibc. Use futimens which is POSIX. Suggested-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
* Drop mtrace calls.Max Filippov2015-05-0410-38/+12
| | | | | | | mtrace is a GNU extension not supported by uClibc and it's believed to not be really used. Drop mtrace() calls and #include <mcheck.h>. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
* Link against standalone argp libraryAnthony G. Basile2015-05-048-31/+81
| | | | | | | | | | | | | | argp is not part of POSIX standards and not provided by uClibc or some other standard C libraries. However, it is possible to link against a breakout argp library. One is provided at http://www.lysator.liu.se/~nisse/misc/ This patch tests if libc provides argp otherwise it adds the linker flag -largp where needed in the build system. Signed-off-by: Anthony G. Basile <blueness@gentoo.org> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
* configure: fix enable_demangler settingMax Filippov2015-05-032-2/+6
| | | | | | | Add missing comma to AS_IF, otherwise enable_demangler is always set to 'no'. Canonicalize tests. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
* tests: Split run-stack tests to support missing demangler.Mark Wielaard2015-05-017-14/+125
| | | | | | SKIP tests that need a demangler if it is not there. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* configure: print feature settings overviewMark Wielaard2015-05-014-5/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | elfutils can be configured in various ways. But we expect certain settings for the features that we explicitly support. Print an overview of all settings, plus their recommended setting, at the end of the configure run. ===================================================================== elfutils: 0.161 (eu_version: 161) ===================================================================== Prefix : /opt/local/install/elfutils Program prefix ("eu-" recommended) : eu- Source code location : /home/mark/src/elfutils Maintainer mode : yes libebl modules subdirectory : elfutils build arch : x86_64-unknown-linux-gnu RECOMMENDED FEATURES (should all be yes) gzip support : yes bzip2 support : yes lzma/xz support : yes libstdc++ demangle support : yes File textrel check : yes Symbol versioning : yes NOT RECOMMENDED FEATURES (should all be no) Experimental thread safety : no OTHER FEATURES Deterministic archives by default : false Native language support : yes EXTRA TEST FEATURES (used with make check) debug branch prediction : no gprof support : no gcov support : no run all tests under valgrind : no use rpath in tests : no test biarch : yes Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Update elf.h from glibc.Mark Wielaard2015-04-284-13/+192
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf: Fix cie_offset calculation comparison on 32bit.Mark Wielaard2015-04-282-2/+8
| | | | | | | | | 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 <mjw@redhat.com>
* libdw: Undefined behavior in get_sleb128_step.Mark Wielaard2015-04-282-4/+27
| | | | | | | | | | gcc -fsanitize=undefined pointed out that for too big sleb128 values we could shift into the sign bit. So for sleb128 values that have to fit in a (signed) int64_t variable reduce the max number of steps by one. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf: Check all offsets used in print_gdb_index_section against d_size.Mark Wielaard2015-04-282-2/+18
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf: Always try to print some debug section information.Mark Wielaard2015-04-282-2/+4
| | | | | | | | 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 <mjw@redhat.com>
* readelf: Add overflow checking to print_gdb_index_section dataend checks.Mark Wielaard2015-04-282-9/+20
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Allow disabling symbol versioning at configure timeMax Filippov2015-04-2310-8/+42
| | | | | | | | | | | | | Due to missing symbol versioning support in uClibc calls to versioned functions that internally call different version of themselves results in infinite recursion. Introduce macro SYMBOL_VERSIONING and use it instead of plain SHARED to decide whether symbol versioning is needed. Control this macro definition with new configure option --disable-symbol-versioning. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>