diff options
| author | 2022-12-06 11:27:00 -0500 | |
|---|---|---|
| committer | 2022-12-06 11:27:00 -0500 | |
| commit | 4b7e73e0a6d72126efebecf3c7003b12106fcab8 (patch) | |
| tree | fd978bf5e08867d86f248ca49884f6b34de6aed3 | |
| parent | Merge pull request #9390 from lioncash/keyboard (diff) | |
| parent | reporter: Pass by const reference where applicable (diff) | |
| download | yuzu-4b7e73e0a6d72126efebecf3c7003b12106fcab8.tar.gz yuzu-4b7e73e0a6d72126efebecf3c7003b12106fcab8.tar.xz yuzu-4b7e73e0a6d72126efebecf3c7003b12106fcab8.zip | |
Merge pull request #9392 from lioncash/reporter
reporter: Eliminate undefined behavior in SaveErrorReport
Diffstat (limited to '')
| -rw-r--r-- | src/core/reporter.cpp | 35 | ||||
| -rw-r--r-- | src/core/reporter.h | 16 |
2 files changed, 26 insertions, 25 deletions
diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index 6e21296f6..77821e047 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp | |||
| @@ -38,7 +38,7 @@ std::string GetTimestamp() { | |||
| 38 | 38 | ||
| 39 | using namespace nlohmann; | 39 | using namespace nlohmann; |
| 40 | 40 | ||
| 41 | void SaveToFile(json json, const std::filesystem::path& filename) { | 41 | void SaveToFile(const json& json, const std::filesystem::path& filename) { |
| 42 | if (!Common::FS::CreateParentDirs(filename)) { | 42 | if (!Common::FS::CreateParentDirs(filename)) { |
| 43 | LOG_ERROR(Core, "Failed to create path for '{}' to save report!", | 43 | LOG_ERROR(Core, "Failed to create path for '{}' to save report!", |
| 44 | Common::FS::PathToUTF8String(filename)); | 44 | Common::FS::PathToUTF8String(filename)); |
| @@ -81,8 +81,8 @@ json GetReportCommonData(u64 title_id, Result result, const std::string& timesta | |||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | json GetProcessorStateData(const std::string& architecture, u64 entry_point, u64 sp, u64 pc, | 83 | json GetProcessorStateData(const std::string& architecture, u64 entry_point, u64 sp, u64 pc, |
| 84 | u64 pstate, std::array<u64, 31> registers, | 84 | u64 pstate, const std::array<u64, 31>& registers, |
| 85 | std::optional<std::array<u64, 32>> backtrace = {}) { | 85 | const std::optional<std::array<u64, 32>>& backtrace = {}) { |
| 86 | auto out = json{ | 86 | auto out = json{ |
| 87 | {"entry_point", fmt::format("{:016X}", entry_point)}, | 87 | {"entry_point", fmt::format("{:016X}", entry_point)}, |
| 88 | {"sp", fmt::format("{:016X}", sp)}, | 88 | {"sp", fmt::format("{:016X}", sp)}, |
| @@ -224,11 +224,11 @@ void Reporter::SaveCrashReport(u64 title_id, Result result, u64 set_flags, u64 e | |||
| 224 | 224 | ||
| 225 | out["processor_state"] = std::move(proc_out); | 225 | out["processor_state"] = std::move(proc_out); |
| 226 | 226 | ||
| 227 | SaveToFile(std::move(out), GetPath("crash_report", title_id, timestamp)); | 227 | SaveToFile(out, GetPath("crash_report", title_id, timestamp)); |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | void Reporter::SaveSvcBreakReport(u32 type, bool signal_debugger, u64 info1, u64 info2, | 230 | void Reporter::SaveSvcBreakReport(u32 type, bool signal_debugger, u64 info1, u64 info2, |
| 231 | std::optional<std::vector<u8>> resolved_buffer) const { | 231 | const std::optional<std::vector<u8>>& resolved_buffer) const { |
| 232 | if (!IsReportingEnabled()) { | 232 | if (!IsReportingEnabled()) { |
| 233 | return; | 233 | return; |
| 234 | } | 234 | } |
| @@ -250,7 +250,7 @@ void Reporter::SaveSvcBreakReport(u32 type, bool signal_debugger, u64 info1, u64 | |||
| 250 | 250 | ||
| 251 | out["svc_break"] = std::move(break_out); | 251 | out["svc_break"] = std::move(break_out); |
| 252 | 252 | ||
| 253 | SaveToFile(std::move(out), GetPath("svc_break_report", title_id, timestamp)); | 253 | SaveToFile(out, GetPath("svc_break_report", title_id, timestamp)); |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | void Reporter::SaveUnimplementedFunctionReport(Kernel::HLERequestContext& ctx, u32 command_id, | 256 | void Reporter::SaveUnimplementedFunctionReport(Kernel::HLERequestContext& ctx, u32 command_id, |
| @@ -271,13 +271,13 @@ void Reporter::SaveUnimplementedFunctionReport(Kernel::HLERequestContext& ctx, u | |||
| 271 | 271 | ||
| 272 | out["function"] = std::move(function_out); | 272 | out["function"] = std::move(function_out); |
| 273 | 273 | ||
| 274 | SaveToFile(std::move(out), GetPath("unimpl_func_report", title_id, timestamp)); | 274 | SaveToFile(out, GetPath("unimpl_func_report", title_id, timestamp)); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | void Reporter::SaveUnimplementedAppletReport( | 277 | void Reporter::SaveUnimplementedAppletReport( |
| 278 | u32 applet_id, u32 common_args_version, u32 library_version, u32 theme_color, | 278 | u32 applet_id, u32 common_args_version, u32 library_version, u32 theme_color, |
| 279 | bool startup_sound, u64 system_tick, std::vector<std::vector<u8>> normal_channel, | 279 | bool startup_sound, u64 system_tick, const std::vector<std::vector<u8>>& normal_channel, |
| 280 | std::vector<std::vector<u8>> interactive_channel) const { | 280 | const std::vector<std::vector<u8>>& interactive_channel) const { |
| 281 | if (!IsReportingEnabled()) { | 281 | if (!IsReportingEnabled()) { |
| 282 | return; | 282 | return; |
| 283 | } | 283 | } |
| @@ -308,10 +308,11 @@ void Reporter::SaveUnimplementedAppletReport( | |||
| 308 | out["applet_normal_data"] = std::move(normal_out); | 308 | out["applet_normal_data"] = std::move(normal_out); |
| 309 | out["applet_interactive_data"] = std::move(interactive_out); | 309 | out["applet_interactive_data"] = std::move(interactive_out); |
| 310 | 310 | ||
| 311 | SaveToFile(std::move(out), GetPath("unimpl_applet_report", title_id, timestamp)); | 311 | SaveToFile(out, GetPath("unimpl_applet_report", title_id, timestamp)); |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | void Reporter::SavePlayReport(PlayReportType type, u64 title_id, std::vector<std::vector<u8>> data, | 314 | void Reporter::SavePlayReport(PlayReportType type, u64 title_id, |
| 315 | const std::vector<std::vector<u8>>& data, | ||
| 315 | std::optional<u64> process_id, std::optional<u128> user_id) const { | 316 | std::optional<u64> process_id, std::optional<u128> user_id) const { |
| 316 | if (!IsReportingEnabled()) { | 317 | if (!IsReportingEnabled()) { |
| 317 | return; | 318 | return; |
| @@ -335,12 +336,12 @@ void Reporter::SavePlayReport(PlayReportType type, u64 title_id, std::vector<std | |||
| 335 | out["play_report_type"] = fmt::format("{:02}", static_cast<u8>(type)); | 336 | out["play_report_type"] = fmt::format("{:02}", static_cast<u8>(type)); |
| 336 | out["play_report_data"] = std::move(data_out); | 337 | out["play_report_data"] = std::move(data_out); |
| 337 | 338 | ||
| 338 | SaveToFile(std::move(out), GetPath("play_report", title_id, timestamp)); | 339 | SaveToFile(out, GetPath("play_report", title_id, timestamp)); |
| 339 | } | 340 | } |
| 340 | 341 | ||
| 341 | void Reporter::SaveErrorReport(u64 title_id, Result result, | 342 | void Reporter::SaveErrorReport(u64 title_id, Result result, |
| 342 | std::optional<std::string> custom_text_main, | 343 | const std::optional<std::string>& custom_text_main, |
| 343 | std::optional<std::string> custom_text_detail) const { | 344 | const std::optional<std::string>& custom_text_detail) const { |
| 344 | if (!IsReportingEnabled()) { | 345 | if (!IsReportingEnabled()) { |
| 345 | return; | 346 | return; |
| 346 | } | 347 | } |
| @@ -354,11 +355,11 @@ void Reporter::SaveErrorReport(u64 title_id, Result result, | |||
| 354 | out["backtrace"] = GetBacktraceData(system); | 355 | out["backtrace"] = GetBacktraceData(system); |
| 355 | 356 | ||
| 356 | out["error_custom_text"] = { | 357 | out["error_custom_text"] = { |
| 357 | {"main", *custom_text_main}, | 358 | {"main", custom_text_main.value_or("")}, |
| 358 | {"detail", *custom_text_detail}, | 359 | {"detail", custom_text_detail.value_or("")}, |
| 359 | }; | 360 | }; |
| 360 | 361 | ||
| 361 | SaveToFile(std::move(out), GetPath("error_report", title_id, timestamp)); | 362 | SaveToFile(out, GetPath("error_report", title_id, timestamp)); |
| 362 | } | 363 | } |
| 363 | 364 | ||
| 364 | void Reporter::SaveFSAccessLog(std::string_view log_message) const { | 365 | void Reporter::SaveFSAccessLog(std::string_view log_message) const { |
diff --git a/src/core/reporter.h b/src/core/reporter.h index 68755cbde..9fdb9d6c1 100644 --- a/src/core/reporter.h +++ b/src/core/reporter.h | |||
| @@ -36,7 +36,7 @@ public: | |||
| 36 | 36 | ||
| 37 | // Used by syscall svcBreak | 37 | // Used by syscall svcBreak |
| 38 | void SaveSvcBreakReport(u32 type, bool signal_debugger, u64 info1, u64 info2, | 38 | void SaveSvcBreakReport(u32 type, bool signal_debugger, u64 info1, u64 info2, |
| 39 | std::optional<std::vector<u8>> resolved_buffer = {}) const; | 39 | const std::optional<std::vector<u8>>& resolved_buffer = {}) const; |
| 40 | 40 | ||
| 41 | // Used by HLE service handler | 41 | // Used by HLE service handler |
| 42 | void SaveUnimplementedFunctionReport(Kernel::HLERequestContext& ctx, u32 command_id, | 42 | void SaveUnimplementedFunctionReport(Kernel::HLERequestContext& ctx, u32 command_id, |
| @@ -44,10 +44,10 @@ public: | |||
| 44 | const std::string& service_name) const; | 44 | const std::string& service_name) const; |
| 45 | 45 | ||
| 46 | // Used by stub applet implementation | 46 | // Used by stub applet implementation |
| 47 | void SaveUnimplementedAppletReport(u32 applet_id, u32 common_args_version, u32 library_version, | 47 | void SaveUnimplementedAppletReport( |
| 48 | u32 theme_color, bool startup_sound, u64 system_tick, | 48 | u32 applet_id, u32 common_args_version, u32 library_version, u32 theme_color, |
| 49 | std::vector<std::vector<u8>> normal_channel, | 49 | bool startup_sound, u64 system_tick, const std::vector<std::vector<u8>>& normal_channel, |
| 50 | std::vector<std::vector<u8>> interactive_channel) const; | 50 | const std::vector<std::vector<u8>>& interactive_channel) const; |
| 51 | 51 | ||
| 52 | enum class PlayReportType { | 52 | enum class PlayReportType { |
| 53 | Old, | 53 | Old, |
| @@ -56,13 +56,13 @@ public: | |||
| 56 | System, | 56 | System, |
| 57 | }; | 57 | }; |
| 58 | 58 | ||
| 59 | void SavePlayReport(PlayReportType type, u64 title_id, std::vector<std::vector<u8>> data, | 59 | void SavePlayReport(PlayReportType type, u64 title_id, const std::vector<std::vector<u8>>& data, |
| 60 | std::optional<u64> process_id = {}, std::optional<u128> user_id = {}) const; | 60 | std::optional<u64> process_id = {}, std::optional<u128> user_id = {}) const; |
| 61 | 61 | ||
| 62 | // Used by error applet | 62 | // Used by error applet |
| 63 | void SaveErrorReport(u64 title_id, Result result, | 63 | void SaveErrorReport(u64 title_id, Result result, |
| 64 | std::optional<std::string> custom_text_main = {}, | 64 | const std::optional<std::string>& custom_text_main = {}, |
| 65 | std::optional<std::string> custom_text_detail = {}) const; | 65 | const std::optional<std::string>& custom_text_detail = {}) const; |
| 66 | 66 | ||
| 67 | void SaveFSAccessLog(std::string_view log_message) const; | 67 | void SaveFSAccessLog(std::string_view log_message) const; |
| 68 | 68 | ||