Avoid nullptr deref in profman
Bug: 297362885
Test: Run profman like 297362885#14 says
Change-Id: If7574667945a558438fb4f198e23f0e1cb5df718
diff --git a/profman/profman.cc b/profman/profman.cc
index 25f03fe..0259222 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -794,10 +794,10 @@
return dump_only_;
}
- // Creates the inline-cache portion of a text-profile line. If there is no
- // inline-caches this will be and empty string. Otherwise it will be '@'
- // followed by an IC description matching the format described by ProcessLine
- // below. Note that this will collapse all ICs with the same receiver type.
+ // Creates the inline-cache portion of a text-profile line. If the class def can't be found, or if
+ // there is no inline-caches this will be and empty string. Otherwise it will be '@' followed by
+ // an IC description matching the format described by ProcessLine below. Note that this will
+ // collapse all ICs with the same receiver type.
std::string GetInlineCacheLine(const ProfileCompilationInfo& profile_info,
const dex::MethodId& id,
const DexFile* dex_file,
@@ -815,10 +815,14 @@
std::set<dex::TypeIndex> classes_;
};
std::unordered_map<dex::TypeIndex, IcLineInfo> ics;
+ const dex::ClassDef* class_def = dex_file->FindClassDef(id.class_idx_);
+ if (class_def == nullptr) {
+ // No class def found.
+ return "";
+ }
+
CodeItemInstructionAccessor accessor(
- *dex_file,
- dex_file->GetCodeItem(dex_file->FindCodeItemOffset(*dex_file->FindClassDef(id.class_idx_),
- dex_method_idx)));
+ *dex_file, dex_file->GetCodeItem(dex_file->FindCodeItemOffset(*class_def, dex_method_idx)));
for (const auto& [pc, ic_data] : *inline_caches) {
const Instruction& inst = accessor.InstructionAt(pc);
const dex::MethodId& target = dex_file->GetMethodId(inst.VRegB());