Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: chet.ramey@case.edu, bug-readline@gnu.org
Cc: gdb-patches@sourceware.org, Pedro Alves <palves@redhat.com>
Subject: Re: [Bug-readline] heap-buffer-overflow in update_line
Date: Thu, 23 May 2019 19:28:00 -0000	[thread overview]
Message-ID: <17c0fa1d-7df4-5204-a8e6-104239d66e3c@suse.de> (raw)
In-Reply-To: <f0529a5e-adb8-b451-3a89-e903172a2438@case.edu>

[-- Attachment #1: Type: text/plain, Size: 1229 bytes --]

On 23-05-19 14:38, Chet Ramey wrote:
> On 5/23/19 3:33 AM, Tom de Vries wrote:
> 
>> Using this additional bit:
>> ...
>> @@ -528,6 +533,8 @@ rl_redisplay ()
>>        init_line_structures (0);
>>        rl_on_new_line ();
>>      }
>> +  else if (line_size <= _rl_screenwidth)
>> +    init_line_structures (_rl_screenwidth + 1);
>>
>>    /* Draw the line into the buffer. */
>>    cpos_buffer_position = -1;
>> ...
>> I managed to fix the assert also in this scenario, and managed to run
>> the entire gdb testsuite without triggering the assert.
>>
>> Is that a good code change?
> 
> It looks like it will solve that problem, and perhaps more. Thanks for the
> patch.

I did a further test-run to see if the original problem (PR24514 -
heap-buffer-overflow in update_line for utf8-identifiers.exp:
https://sourceware.org/bugzilla/show_bug.cgi?id=24514 ) was fixed, which
turned out not to be the case.

I've analyzed this, and found it to be caused by the
init_line_structures part of the patch changing line_size, which does
not force a reallloc. I've fixed this by changing minsize instead.

Attached patch passes gdb regression testsuite with the assert enabled,
and with gdb build with -fsanitize=address.

Thanks,
- Tom


[-- Attachment #2: 0002-tentative.patch --]
[-- Type: text/x-patch, Size: 738 bytes --]

tentative

---
 readline/display.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/readline/display.c b/readline/display.c
index 712ca79b6d..f34ad05444 100644
--- a/readline/display.c
+++ b/readline/display.c
@@ -452,6 +452,9 @@ init_line_structures (minsize)
 {
   register int n;
 
+  if (minsize <= _rl_screenwidth)	/* XXX - for gdb */
+    minsize = _rl_screenwidth + 1;
+
   if (invisible_line == 0)	/* initialize it */
     {
       if (line_size < minsize)
@@ -528,6 +531,8 @@ rl_redisplay ()
       init_line_structures (0);
       rl_on_new_line ();
     }
+  else if (line_size <= _rl_screenwidth)
+    init_line_structures (_rl_screenwidth + 1);
 
   /* Draw the line into the buffer. */
   cpos_buffer_position = -1;

  reply	other threads:[~2019-05-23 19:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <52f237e9-83e8-2a97-4766-e60b867ab914@suse.de>
     [not found] ` <d29fbf1f-d33e-77f6-90ed-0eb3779a027c@case.edu>
2019-05-17 14:59   ` Tom de Vries
2019-05-17 15:34     ` Chet Ramey
2019-05-20 20:14     ` Chet Ramey
2019-05-23  7:33       ` Tom de Vries
2019-05-23 12:38         ` Chet Ramey
2019-05-23 19:28           ` Tom de Vries [this message]
2019-05-24 13:08             ` Chet Ramey

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=17c0fa1d-7df4-5204-a8e6-104239d66e3c@suse.de \
    --to=tdevries@suse.de \
    --cc=bug-readline@gnu.org \
    --cc=chet.ramey@case.edu \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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