public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "Björn Schäpers" <gcc@hazardy.de>
Cc: libstdc++@gcc.gnu.org, gcc Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: Add error handler for <stacktrace>
Date: Wed, 30 Nov 2022 13:05:03 +0000	[thread overview]
Message-ID: <CACb0b4m1ayRFeV3xcbsbozw+ftVrDKbQp9Db64pVHhYCMZXMyA@mail.gmail.com> (raw)
In-Reply-To: <CACb0b4kruVE28cZZh-ALpocSH+BdkYS_DXHC-iU+2MDm33SgNA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

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!

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3161 bytes --]

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();

      reply	other threads:[~2022-11-30 13:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 21:41 Björn Schäpers
2022-11-30  6:04 ` François Dumont
2022-11-30 11:54   ` Jonathan Wakely
2022-11-30 11:57     ` Jonathan Wakely
2022-11-30 13:07       ` Jonathan Wakely
2022-11-30 18:00         ` François Dumont
2022-12-06 21:44           ` Jonathan Wakely
2022-12-07 17:58             ` François Dumont
2022-12-07 20:06               ` Jonathan Wakely
2022-11-30 18:17         ` François Dumont
2022-11-30 19:20   ` Björn Schäpers
2022-11-30 12:31 ` Jonathan Wakely
2022-11-30 13:05   ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACb0b4m1ayRFeV3xcbsbozw+ftVrDKbQp9Db64pVHhYCMZXMyA@mail.gmail.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@hazardy.de \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).