From e7f9f58fa408ac89ed1ce709494d84090b63bff0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 5 Dec 2022 21:26:00 -0500 Subject: reporter: Eliminate undefined behavior in SaveErrorReport The optionals are unconditionally dereferenced when setting the custom error text, and in a few cases this function is called using the default value of the optionals. This means we'd be dereferencing uninitialized storage. Since they're used unconditionally, we can use value_or to set a default when storage is uninitialized. --- src/core/reporter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/reporter.cpp') diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index 6e21296f6..543b91d9a 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -339,8 +339,8 @@ void Reporter::SavePlayReport(PlayReportType type, u64 title_id, std::vector custom_text_main, - std::optional custom_text_detail) const { + const std::optional& custom_text_main, + const std::optional& custom_text_detail) const { if (!IsReportingEnabled()) { return; } @@ -354,8 +354,8 @@ void Reporter::SaveErrorReport(u64 title_id, Result result, out["backtrace"] = GetBacktraceData(system); out["error_custom_text"] = { - {"main", *custom_text_main}, - {"detail", *custom_text_detail}, + {"main", custom_text_main.value_or("")}, + {"detail", custom_text_detail.value_or("")}, }; SaveToFile(std::move(out), GetPath("error_report", title_id, timestamp)); -- cgit v1.2.3