[PATCH] libstdc++: Add error handler for <stacktrace>
Jonathan Wakely
jwakely@redhat.com
Wed Nov 30 13:05:03 GMT 2022
Resending with the typo in the mailing list address fixed...
On Wed, 30 Nov 2022 at 12:31, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Tue, 29 Nov 2022 at 21:41, Björn Schäpers wrote:
> >
> > From: Björn Schäpers <bjoern@hazardy.de>
> >
> > Not providing an error handler results in a nullpointer dereference when
> > an error occurs.
>
>
> Thanks for the patch. This looks small enough to not require legal
> paperwork, but if you intend to make further contributions (and I hope
> you do!) please note the process at https://gcc.gnu.org/dco.html or
> complete the paperwork for a copyright assignment to the FSF,
> whichever you prefer.
>
> I'm going to test and commit the attached patch, which replaces your
> __backtrace_error_handler with a static member function so that we
> don't make the name visible in the global namespace.
>
> Thanks again!
-------------- next part --------------
commit 0e32de31f34a88b941acd2f471ba6e8e945372cf
Author: Björn Schäpers <bjoern@hazardy.de>
Date: Wed Nov 30 12:04:16 2022
libstdc++: Add error handler for <stacktrace>
Not providing an error handler results in a null pointer dereference
when an error occurs.
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
* include/std/stacktrace (stacktrace_entry::_S_err_handler): New
static function.
(stacktrace_entry, basic_stacktrace): Pass &_S_err_handler to
all calls to libbacktrace.
diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace
index e7cbbee5638..ec3335e89d8 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -155,11 +155,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Allocator> friend class basic_stacktrace;
+ static void _S_err_handler(void*, const char*, int) { }
+
static __glibcxx_backtrace_state*
_S_init()
{
static __glibcxx_backtrace_state* __state
- = __glibcxx_backtrace_create_state(nullptr, 1, nullptr, nullptr);
+ = __glibcxx_backtrace_create_state(nullptr, 1, _S_err_handler, nullptr);
return __state;
}
@@ -192,7 +194,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __function != nullptr;
};
const auto __state = _S_init();
- if (::__glibcxx_backtrace_pcinfo(__state, _M_pc, +__cb, nullptr, &__data))
+ if (::__glibcxx_backtrace_pcinfo(__state, _M_pc, +__cb, _S_err_handler,
+ &__data))
return true;
if (__desc && __desc->empty())
{
@@ -201,8 +204,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__symname)
*static_cast<_Data*>(__data)->_M_desc = _S_demangle(__symname);
};
- if (::__glibcxx_backtrace_syminfo(__state, _M_pc, +__cb2, nullptr,
- &__data))
+ if (::__glibcxx_backtrace_syminfo(__state, _M_pc, +__cb2,
+ _S_err_handler, &__data))
return true;
}
return false;
@@ -252,7 +255,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (auto __cb = __ret._M_prepare()) [[likely]]
{
auto __state = stacktrace_entry::_S_init();
- if (__glibcxx_backtrace_simple(__state, 1, __cb, nullptr,
+ if (__glibcxx_backtrace_simple(__state, 1, __cb,
+ stacktrace_entry::_S_err_handler,
std::__addressof(__ret)))
__ret._M_clear();
}
@@ -270,7 +274,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (auto __cb = __ret._M_prepare()) [[likely]]
{
auto __state = stacktrace_entry::_S_init();
- if (__glibcxx_backtrace_simple(__state, __skip + 1, __cb, nullptr,
+ if (__glibcxx_backtrace_simple(__state, __skip + 1, __cb,
+ stacktrace_entry::_S_err_handler,
std::__addressof(__ret)))
__ret._M_clear();
}
@@ -294,7 +299,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
auto __state = stacktrace_entry::_S_init();
int __err = __glibcxx_backtrace_simple(__state, __skip + 1, __cb,
- nullptr,
+ stacktrace_entry::_S_err_handler,
std::__addressof(__ret));
if (__err < 0)
__ret._M_clear();
More information about the Libstdc++
mailing list