public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
Subject: Re: [RFA 1/2] Fix regressions for multi breakpoints command line setting/clearing
Date: Fri, 10 Aug 2018 00:35:00 -0000	[thread overview]
Message-ID: <878t5fhxdl.fsf@tromey.com> (raw)
In-Reply-To: <1533845999.1860.1.camel@skynet.be> (Philippe Waroquiers's	message of "Thu, 09 Aug 2018 22:19:59 +0200")

>>>>> "Philippe" == Philippe Waroquiers <philippe.waroquiers@skynet.be> writes:

Philippe> There was also a second regression which was fixed by the patch
Philippe> suggested in the RFA 1/2 (and the test in RFA 2/2 was checking
Philippe> the regression).
Philippe> Will you add the fix for the second regression (and the test)
Philippe> in another commit ?

Yeah, I can rebase your patches on top of this one.

>> if (repeat && *p1 == '\0')
>> -    return saved_command_line;
>> +    {
>> +      xfree (buffer_finish (cmd_line_buffer));
>> +      buffer_grow_str0 (cmd_line_buffer, saved_command_line);
>> +      cmd_line_buffer->used_size = 0;

Philippe> I was somewhat surprised by used_size being set to 0.
Philippe> I am not sure to understand in which case it is supposed to be
Philippe> set to 0 : it is set to 0 in the first few lines of handle_line_of_input
Philippe> with a comment explaining why.
Philippe> I however do not understand why it is set to the string length in
Philippe> the 'Do history expansion' case, and not to 0 : as far as I can see,
Philippe> cmd will be returned as a full line in case of expansion ?

Thanks for noticing this.

I suspect the history case (which doesn't seem to be tested...) is just
wrong and should also set the used size to 0.

I believe the idea being clear the used size is that the buffer still
owns the string, but if the buffer is reused then the string is
considered ok to overwrite.  Which, admittedly, seems odd to me, but
this patch seemed like the least intrusive way to avoid the
use-after-free...

I'll see if I can come up with a test case here.

Philippe> IIUC, the returned value will stay valid as long as the
Philippe> cmd_line_buffer is not destroyed but also only if the buffer is
Philippe> not touched (e.g. no data can be added to it, as otherwise
Philippe> the previously returned value might become dangling).
Philippe> So, for example, the below (pseudo) code would be incorrect:
Philippe>    arg = command_line_input (..., cmd_buffer);
Philippe>    while parsing arg not finished
Philippe>        // here it is forbidden to touch cmd_buffer
Philippe>        // e.g. the below would be bad:
Philippe>        some_other_arg = command_line_input (..., cmd_buffer);

Philippe> So, I am wondering what kind of usage of this function
Philippe> will make the buffer bigger. Maybe worth pointing at the
Philippe> above risk then ?

I can add a comment somewhere.

I don't really understand why this code works the way it does.
It seems unusually convoluted.  At the same time, I didn't want to
completely tear it apart, since it's not clear that's a good use of
one's time.

Tom

  reply	other threads:[~2018-08-10  0:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02 21:26 RFA " Philippe Waroquiers
2018-08-02 21:26 ` [RFA 2/2] Modify gdb.base/commands.exp to test multi breakpoint command setting/clearing Philippe Waroquiers
2018-08-16 15:54   ` Pedro Alves
2018-08-02 21:26 ` [RFA 1/2] Fix regressions for multi breakpoints command line setting/clearing Philippe Waroquiers
2018-08-03 18:29   ` Tom Tromey
2018-08-09  4:57     ` Tom Tromey
2018-08-09 20:20       ` Philippe Waroquiers
2018-08-10  0:35         ` Tom Tromey [this message]
2018-08-10  3:05           ` Tom Tromey
2018-08-10  3:13             ` Tom Tromey
2018-08-10 16:07               ` Tom Tromey
2018-08-11 20:38                 ` Tom Tromey
2018-08-13 21:32                   ` Philippe Waroquiers
2018-08-14 15:02               ` Pedro Alves
2018-08-14 18:33                 ` Tom Tromey
2018-08-15 18:24                   ` Tom Tromey
2018-08-16 15:34                     ` Pedro Alves
2018-08-17 23:12                       ` Tom Tromey
2018-08-21 18:01   ` Tom Tromey
2018-08-25 19:17     ` Philippe Waroquiers

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=878t5fhxdl.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=philippe.waroquiers@skynet.be \
    /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).