public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Simon Marchi <simon.marchi@efficios.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: consider null terminator for length arguments of value_cstring calls
Date: Tue, 13 Jul 2021 18:07:23 +0100	[thread overview]
Message-ID: <b44aca00-aa79-81c8-53ba-dfbe7dda87cf@palves.net> (raw)
In-Reply-To: <20210713153142.3957666-1-simon.marchi@efficios.com>

On 2021-07-13 4:31 p.m., Simon Marchi via Gdb-patches wrote:

> A way to expose the bug, as implemented in the new test, is to make an
> inferior function call with this value, using a function that reads the
> string until the null terminator.  That allocates some memory in the
> inferior for the string and copies it.  If the null terminator is
> missing, the function will read past the allocated buffer, possibly
> causing a crash.  In practice, the memory following the buffer must
> pretty often be zeroed-out, because I didn't see a crash just with this.
> But if we compile the inferior program with AddressSanitizer, then the
> out-of-bounds access causes a crash systematically.
> 
> It would be nice to find a test that does not require compiling the
> inferior program with AddressSanitizer, if somebody has a better idea,
> but at least I think it's better than no test.

Do we need to run a program at all?  How about simply something based on this?

Before patch:

 (gdb) maint set test-settings string foo
 (gdb) p $_gdb_maint_setting("test-settings string")
 $1 = "foo"
 (gdb) p $_gdb_maint_setting("test-settings string")[0]
 $2 = 102 'f'
 (gdb) p $_gdb_maint_setting("test-settings string")[1]
 $3 = 111 'o'
 (gdb) p $_gdb_maint_setting("test-settings string")[2]
 $4 = 111 'o'
 (gdb) p $_gdb_maint_setting("test-settings string")[3]
 no such vector element

After patch:

 (gdb) maint set test-settings string foo
 (gdb) p $_gdb_maint_setting("test-settings string")
 $1 = "foo"
 (gdb) p $_gdb_maint_setting("test-settings string")[0]
 $2 = 102 'f'
 (gdb) p $_gdb_maint_setting("test-settings string")[1]
 $3 = 111 'o'
 (gdb) p $_gdb_maint_setting("test-settings string")[2]
 $4 = 111 'o'
 (gdb) p $_gdb_maint_setting("test-settings string")[3]
 $5 = 0 '\000'
 (gdb) p $_gdb_maint_setting("test-settings string")[4]
 no such vector element

  reply	other threads:[~2021-07-13 17:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 15:31 Simon Marchi
2021-07-13 17:07 ` Pedro Alves [this message]
2021-07-13 18:44   ` Simon Marchi
2021-07-14 10:25     ` Pedro Alves
2021-07-14 13:50       ` Simon Marchi
2021-07-15 14:29         ` Pedro Alves
2021-07-23 19:37           ` Simon Marchi
2021-07-21 15:21       ` 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=b44aca00-aa79-81c8-53ba-dfbe7dda87cf@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).