From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <pedro@palves.net>, gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: Re: [PATCH RESEND] gdb: remove static buffer in command_line_input
Date: Fri, 16 Dec 2022 08:38:16 -0500 [thread overview]
Message-ID: <8a091e68-2609-b28d-3945-9b763ed9b6d0@polymtl.ca> (raw)
In-Reply-To: <1e61d9cc-00e0-56d6-c232-96d465a78782@palves.net>
On 12/16/22 08:21, Pedro Alves wrote:
> On 2022-12-15 7:06 p.m., Simon Marchi via Gdb-patches wrote:
>> else
>> {
>> /* Copy whole line including terminating null, and we're
>> done. */
>> - buffer_grow (cmd_line_buffer, rl, len + 1);
>> - cmd = cmd_line_buffer->buffer;
>> + cmd_line_buffer.append (rl, len + 1);
>> + return true;
>
> std::string is guaranteed to be null terminated, but, it can also hold
> \0 characters in the middle of the string. Isn't that
>
> cmd_line_buffer.append (rl, len + 1);
>
> ending up with an embedded \0 at the end of the string, with cmd_line_buffer.size() accounting for it?
Argh, yes! I rewrote this patch from scratch multiple times until I got
something satisfactory, and I know I changed that in a previous
iteration, because I remember having that thought.
Here's a patch to fix it:
From 8757d2ec9edf2ae0b77039ca0ecc9ca32fd87256 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Fri, 16 Dec 2022 08:34:56 -0500
Subject: [PATCH] gdb: don't copy final null character in
command_line_append_input_line
The modified std::string::append call currently copies the null
character from the source string, leaving the std::string with a null
character in its content, part of its size, in addition to the null
character managed by the std::string itself We don't want to copy that
null character, so remove that "+ 1".
Change-Id: I412fe9bd6b08e7ce7604ef5d8038b62f1a784c9b
---
gdb/event-top.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/event-top.c b/gdb/event-top.c
index fa86a89e4a19..fa9e1f3f6a73 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -640,7 +640,7 @@ command_line_append_input_line (std::string &cmd_line_buffer, const char *rl)
{
/* Copy whole line including terminating null, and we're
done. */
- cmd_line_buffer.append (rl, len + 1);
+ cmd_line_buffer.append (rl, len);
return true;
}
}
base-commit: e60a615dde5d6674a6488b74afe807a775551407
--
2.38.1
next prev parent reply other threads:[~2022-12-16 13:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-15 19:06 Simon Marchi
2022-12-15 21:44 ` Tom Tromey
2022-12-16 2:49 ` Simon Marchi
2022-12-16 13:21 ` Pedro Alves
2022-12-16 13:38 ` Simon Marchi [this message]
2022-12-16 14:11 ` Pedro Alves
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=8a091e68-2609-b28d-3945-9b763ed9b6d0@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=jan.vrany@labware.com \
--cc=pedro@palves.net \
/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).