AddressSpace: fix DWARF based unwinding handling on Android
authorSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 5 Apr 2017 21:29:38 +0000 (21:29 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 5 Apr 2017 21:29:38 +0000 (21:29 +0000)
It is possible that there are no program headers in the module.  Do not
attempt to dereference nullptr as a program header.

llvm-svn: 299591

libunwind/src/AddressSpace.hpp

index ab6e0d5..54b258e 100644 (file)
@@ -394,8 +394,11 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
         size_t object_length;
 #if defined(__ANDROID__)
         Elf_Addr image_base =
-            reinterpret_cast<Elf_Addr>(pinfo->dlpi_phdr) -
-            reinterpret_cast<const Elf_Phdr *>(pinfo->dlpi_phdr)->p_offset;
+            pinfo->dlpi_phnum
+                ? reinterpret_cast<Elf_Addr>(pinfo->dlpi_phdr) -
+                      reinterpret_cast<const Elf_Phdr *>(pinfo->dlpi_phdr)
+                          ->p_offset
+                : 0;
 #endif
 
         for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {