From: Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org>
To: Tom Tromey <tom@tromey.com>,
Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH][PR gdb/27133] Avoid use after free with logging and debug redirect
Date: Mon, 4 Jan 2021 23:29:18 +0000 [thread overview]
Message-ID: <e41697c8-6257-ecf7-7821-d39c6854428c@lancelotsix.com> (raw)
In-Reply-To: <87pn2ke9eb.fsf@tromey.com>
On 04/01/2021 20:26, Tom Tromey wrote:
>>>>>> "Lancelot" == Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org> writes:
> Lancelot> My copyright assignment has not yet been signed by FSF, but the change
> Lancelot> should be small enough not to require it. Otherwise, it will need to
> Lancelot> wait a few more days I guess.
>
> I don't know the state of this -- could you say?
Hi,
I have signed my end of the document, and am waiting for it to be also
signed by the FSF. I should be quite close to the end of the procedure I
guess. I’ll let you know when this is validated. In the meantime, I have
few patch I still need to update according to reviews.
> Lancelot> gdb/ChangeLog:
>
> Lancelot> PR gdb/27133
> Lancelot> * cli/cli-interp.c (cli_interp_base::set_logging): Ensure the
> Lancelot> unique_ptr is released when the wrapped pointer is kept for later
> Lancelot> use.
>
> Thanks. Looking at the code I feel like there's probably some cleaner
> way to do this, but this patch is ok regardless.
Yes, this feels a bit hacky, but I have gone through few variations and
up until now none were as straight forward as I’d like them to be (hence
the bloc of comment.). Here is another approach you might prefer:
---
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 424264a80e..34afc94d5a 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -417,7 +417,7 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
ui_file *logfile_p = nullptr;
if (logging_redirect || debug_redirect)
{
- logfile_p = logfile.get ();
+ logfile_p = logfile.release ();
saved_output.file_to_delete = logfile_p;
}
@@ -426,7 +426,13 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
ui_file *tee = nullptr;
if (!logging_redirect || !debug_redirect)
{
- tee = new tee_file (gdb_stdout, std::move (logfile));
+ /* If logfile_p not nullptr, this is because it took ownership
+ of the logfile. In this case transfer the ownership from
+ logfile_p to tee, otherwise just transfer ownership directly
+ from logfile to tee. */
+ tee = new tee_file (gdb_stdout, (logfile_p == nullptr ?
+ std::move (logfile) :
+ ui_file_up (logfile_p)));
saved_output.file_to_delete = tee;
}
This option might makes it easier to follow ownership.
Lancelot
> Tom
next prev parent reply other threads:[~2021-01-04 23:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-01 20:11 Lancelot SIX via Gdb-patches
2021-01-04 20:26 ` Tom Tromey
2021-01-04 23:29 ` Lancelot SIX via Gdb-patches [this message]
2021-01-27 22:20 ` Lancelot SIX via Gdb-patches
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=e41697c8-6257-ecf7-7821-d39c6854428c@lancelotsix.com \
--to=gdb-patches@sourceware.org \
--cc=lsix@lancelotsix.com \
--cc=tom@tromey.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