Implement a safer version of GetCrashInfoFromException (#3652)

* Implement a safer version of GetCrashInfoFromException

`abi::__cxa_current_exception_type()` can return `null`, handle this properly

* Update src/stacktraces.cpp

Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>

* Update src/stacktraces.cpp

Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>

Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>
This commit is contained in:
UdjinM6 2020-08-14 14:42:42 +03:00 committed by pasta
parent 4414b5c3c7
commit bd5c047e28
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -690,32 +690,34 @@ crash_info GetCrashInfoFromException(const std::exception_ptr& e)
std::string type;
std::string what;
auto getExceptionType = [&]() -> std::string {
auto type = abi::__cxa_current_exception_type();
if (type && (strlen(type->name()) > 0)) {
return DemangleSymbol(type->name());
}
return "<unknown>";
};
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 = "<unknown>";
}
if (type.empty()) {
type = "<unknown>";
} else {
type = DemangleSymbol(type);
}
ci.crashDescription += strprintf("type=%s, what=\"%s\"", type, what);
auto stackframes = GetExceptionStacktrace(e);