mirror of
https://github.com/RGBCube/serenity
synced 2025-05-26 01:55:08 +00:00
Profiler: load_from_perfcore_file: handle invalid JSON gracefully
This commit is contained in:
parent
5735fb47f3
commit
fc9f79fe01
1 changed files with 6 additions and 3 deletions
|
@ -259,14 +259,17 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
|
|||
return String::formatted("Unable to open {}, error: {}", path, file->error_string());
|
||||
|
||||
auto json = JsonValue::from_string(file->read_all());
|
||||
ASSERT(json.has_value());
|
||||
if (!json.value().is_object())
|
||||
if (!json.has_value() || !json.value().is_object())
|
||||
return String { "Invalid perfcore format (not a JSON object)" };
|
||||
|
||||
auto& object = json.value().as_object();
|
||||
auto executable_path = object.get("executable").to_string();
|
||||
|
||||
auto coredump = CoreDump::Reader::create(String::formatted("/tmp/profiler_coredumps/{}", object.get("pid").as_u32()));
|
||||
auto pid = object.get("pid");
|
||||
if (!pid.is_u32())
|
||||
return String { "Invalid perfcore format (no process ID)" };
|
||||
|
||||
auto coredump = CoreDump::Reader::create(String::formatted("/tmp/profiler_coredumps/{}", pid.as_u32()));
|
||||
if (!coredump)
|
||||
return String { "Could not open coredump" };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue