From fc9f79fe01e2f33cb741e29ea432efba47ac6a4a Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Sat, 9 Jan 2021 03:56:52 +0000 Subject: [PATCH] Profiler: load_from_perfcore_file: handle invalid JSON gracefully --- DevTools/Profiler/Profile.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/DevTools/Profiler/Profile.cpp b/DevTools/Profiler/Profile.cpp index a56f41baf5..548d719477 100644 --- a/DevTools/Profiler/Profile.cpp +++ b/DevTools/Profiler/Profile.cpp @@ -259,14 +259,17 @@ Result, 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" };