summaryrefslogtreecommitdiff
path: root/runtime/elf_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/elf_file.cc')
-rw-r--r--runtime/elf_file.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index 65972359e8..4198905e23 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -488,6 +488,20 @@ bool ElfFileImpl<Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Word,
return false;
}
+ // We'd also like to confirm a shstrtab in program_header_only_ mode (else Open() does this for
+ // us). This is usually the last in an oat file, and a good indicator of whether writing was
+ // successful (or the process crashed and left garbage).
+ if (program_header_only_) {
+ // It might not be mapped, but we can compare against the file size.
+ int64_t offset = static_cast<int64_t>(GetHeader().e_shoff +
+ (GetHeader().e_shstrndx * GetHeader().e_shentsize));
+ if (offset >= file_->GetLength()) {
+ *error_msg = StringPrintf("Shstrtab is not in the mapped ELF file: '%s'",
+ file_->GetPath().c_str());
+ return false;
+ }
+ }
+
return true;
}