From bc1d711dfb7938dfb919fdc252caf4d36799a4a7 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 2 Aug 2020 19:32:18 +0300 Subject: [PATCH 1/3] Implement a safer version of GetCrashInfoFromException `abi::__cxa_current_exception_type()` can return `null`, handle this properly --- src/stacktraces.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/stacktraces.cpp b/src/stacktraces.cpp index 31cd312c4c4c..e0b526ea722f 100644 --- a/src/stacktraces.cpp +++ b/src/stacktraces.cpp @@ -686,32 +686,34 @@ crash_info GetCrashInfoFromException(const std::exception_ptr& e) std::string type; std::string what; + auto getExceptionType = [&]() { + auto type = abi::__cxa_current_exception_type(); + if (type && (strlen(type->name()) > 0)) { + return DemangleSymbol(type->name()); + } + return std::string(""); + }; + try { // rethrow and catch the exception as there is no other way to reliably cast to the real type (not possible with RTTI) std::rethrow_exception(e); } catch (const std::exception& e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (const std::string& e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (const char* e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (int e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (...) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = ""; } - if (type.empty()) { - type = ""; - } else { - type = DemangleSymbol(type); - } - ci.crashDescription += strprintf("type=%s, what=\"%s\"", type, what); auto stackframes = GetExceptionStacktrace(e); From d8b676d630b6c84634e099429abf9ed43f6beef6 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 9 Aug 2020 19:28:34 +0300 Subject: [PATCH 2/3] Update src/stacktraces.cpp Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> --- src/stacktraces.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stacktraces.cpp b/src/stacktraces.cpp index e0b526ea722f..432ab84a6fbc 100644 --- a/src/stacktraces.cpp +++ b/src/stacktraces.cpp @@ -686,7 +686,7 @@ crash_info GetCrashInfoFromException(const std::exception_ptr& e) std::string type; std::string what; - auto getExceptionType = [&]() { + auto getExceptionType = [&]() -> std::string { auto type = abi::__cxa_current_exception_type(); if (type && (strlen(type->name()) > 0)) { return DemangleSymbol(type->name()); From 2429a21b36427698e7630e2623ed5fcb0e425016 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 11 Aug 2020 12:07:56 +0300 Subject: [PATCH 3/3] Update src/stacktraces.cpp Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> --- src/stacktraces.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stacktraces.cpp b/src/stacktraces.cpp index 432ab84a6fbc..4b8e511585d9 100644 --- a/src/stacktraces.cpp +++ b/src/stacktraces.cpp @@ -691,7 +691,7 @@ crash_info GetCrashInfoFromException(const std::exception_ptr& e) if (type && (strlen(type->name()) > 0)) { return DemangleSymbol(type->name()); } - return std::string(""); + return ""; }; try {