Remove dangling soinfo* from elf_readers_map_
If ElfReader::Read fails, then it is hazardous to leave the invalid
ElfReader in the soinfo*->ElfReader table, because a future soinfo
object could happen to have the same address, then reuse the invalid
ElfReader. I'm not sure whether this can break anything, because the
linker would call ElfReader::Read on the invalid object and overwrite
its previous value.
Test: bionic unit tests
Bug: none
Change-Id: Ibabbf559443441b9caeacc34ca165feaafe5e3a7
diff --git a/linker/linker.cpp b/linker/linker.cpp
index ac83cae..090e7f0 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -602,6 +602,11 @@
return start_from_;
}
+ void remove_cached_elf_reader() {
+ CHECK(si_ != nullptr);
+ (*elf_readers_map_).erase(si_);
+ }
+
const ElfReader& get_elf_reader() const {
CHECK(si_ != nullptr);
return (*elf_readers_map_)[si_];
@@ -1272,8 +1277,9 @@
// Read the ELF header and some of the segments.
if (!task->read(realpath.c_str(), file_stat.st_size)) {
- soinfo_free(si);
+ task->remove_cached_elf_reader();
task->set_soinfo(nullptr);
+ soinfo_free(si);
return false;
}