diff options
author | George Burgess IV <gbiv@google.com> | 2017-06-27 16:23:45 -0700 |
---|---|---|
committer | George Burgess IV <gbiv@google.com> | 2017-06-28 15:03:15 -0700 |
commit | 705910094d07ddfc5a3b7a4baab58b0a94bcc691 (patch) | |
tree | f503093f7f1675566233ac00bda745b8a9bcf714 /linker/linker_main.cpp | |
parent | 82d746fb39465e78088aeb11a5dc178cf264d0c0 (diff) |
bionic: fix assorted static analyzer warnings
Warnings:
bionic/libc/bionic/fts.c:722:5: warning: Null passed to a callee that
requires a non-null 1st parameter
bionic/libc/bionic/sched_cpualloc.c:34:25: warning: Result of 'malloc'
is converted to a pointer of type 'cpu_set_t', which is incompatible
with sizeof operand type 'unsigned long'
bionic/linker/linker_main.cpp:315:7: warning: Access to field 'e_type'
results in a dereference of a null pointer (loaded from variable
'elf_hdr')
bionic/linker/linker_main.cpp:493:66: warning: Access to field 'e_phoff'
results in a dereference of a null pointer (loaded from variable
'elf_hdr')
bionic/linker/linker_main.cpp:90:14: warning: Access to field 'next'
results in a dereference of a null pointer (loaded from variable 'prev')
Bug: None
Test: mma; analyzer warnings are gone. CtsBionicTestCases pass.
Change-Id: I699a60c2c6f64c50b9ea06848a680c98a8abb44a
Diffstat (limited to 'linker/linker_main.cpp')
-rw-r--r-- | linker/linker_main.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp index 5dc215f9d..db3697618 100644 --- a/linker/linker_main.cpp +++ b/linker/linker_main.cpp @@ -87,6 +87,7 @@ bool solist_remove_soinfo(soinfo* si) { // prev will never be null, because the first entry in solist is // always the static libdl_info. + CHECK(prev != nullptr); prev->next = si->next; if (si == sonext) { sonext = prev; @@ -307,6 +308,11 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args) { break; } } + + if (si->base == 0) { + async_safe_fatal("Could not find a PHDR: broken executable?"); + } + si->dynamic = nullptr; ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base); @@ -488,6 +494,15 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) { static uintptr_t linktime_addr = reinterpret_cast<uintptr_t>(&linktime_addr); ElfW(Addr) linker_addr = reinterpret_cast<uintptr_t>(&linktime_addr) - linktime_addr; +#if defined(__clang_analyzer__) + // The analyzer assumes that linker_addr will always be null. Make it an + // unknown value so we don't have to mark N places with NOLINTs. + // + // (`+=`, rather than `=`, allows us to sidestep a potential "unused store" + // complaint) + linker_addr += reinterpret_cast<uintptr_t>(raw_args); +#endif + ElfW(Addr) entry_point = args.getauxval(AT_ENTRY); ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_addr); ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_addr + elf_hdr->e_phoff); |