Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Guinevere Larsen <guinevere@redhat.com>,
	Simon Marchi <simon.marchi@efficios.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/solib: pass lm_info, original_name and name to solib constructor
Date: Wed, 4 Jun 2025 00:38:48 -0400	[thread overview]
Message-ID: <0cd026ed-3be2-486b-8f09-effe23f30562@simark.ca> (raw)
In-Reply-To: <0bc50478-6756-4825-8080-031e3aef864a@redhat.com>



On 2025-06-03 19:07, Guinevere Larsen wrote:
>> +    sos.emplace_back (std::move (info), info->name, info->name);
> This is a bad idea. I double checked with c++ folk and while no
> compilers warn about this, if the compiler evaluates things right to
> left (like gcc) this works, but if they evaluate left to right (like
> clang), then info->name will be de-referencing null and segfault. This
> might also depend on ABI, but the end result is the same: fragile at
> best. we'll need something that saves or moves info->name to pass it
> to the emplace_back constructor

Wow, good catch, thanks.  Actually, with C++17, I think the order of
evaluation has been specified from left to right.  So, I think it should
crash regardless of the compiler.  I don't think that the testsuite
exercises that code though on Linux.

A more long-term fix would be to move the name out of lm_info_target (it
doesn't belong there anyway).  But for now I'll change it like so in my
patch:


  for (lm_info_target_up &info : library_list)
    {
      /* Move NAME to a local variable to avoid reading INFO->NAME after having
	 moved info.  */
      std::string name = std::move (info->name);
      sos.emplace_back (std::move (info), name, name);
    }

It seems to be the only occurrence of this problem in the patch.

Simon

      reply	other threads:[~2025-06-04  4:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-03 15:32 Simon Marchi
2025-06-03 23:07 ` Guinevere Larsen
2025-06-04  4:38   ` Simon Marchi [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=0cd026ed-3be2-486b-8f09-effe23f30562@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=guinevere@redhat.com \
    --cc=simon.marchi@efficios.com \
    /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