From: Alan Hayward <Alan.Hayward@arm.com>
To: Pedro Alves <palves@redhat.com>
Cc: Yao Qi <qiyaoltc@gmail.com>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
nd <nd@arm.com>
Subject: Re: [PATCH] Remove MAX_REGISTER_SIZE from py-unwind.c
Date: Thu, 22 Jun 2017 14:36:00 -0000 [thread overview]
Message-ID: <DE02AAD6-7EC8-4810-A605-0221ED6D350C@arm.com> (raw)
In-Reply-To: <8b641cf5-6cdc-5c4e-6f85-eb28f08bed9c@redhat.com>
> On 22 Jun 2017, at 14:22, Pedro Alves <palves@redhat.com> wrote:
>
> On 06/22/2017 02:13 PM, Alan Hayward wrote:
>
>> Ok, pushed with changes as suggested.
>>
>> Patch below.
>
> Sorry, but this looks broken to me.
>
> cached_frame_info is using the trailing array idiom ...
>
>> @@ -93,7 +84,7 @@ typedef struct
>> /* Length of the `reg' array below. */
>> int reg_count;
>>
>> - struct reg_info reg[];
>> + cached_reg_t reg[];
>> } cached_frame_info;
>>
>
>>
>> - cached_frame
>> - = ((cached_frame_info *)
>> - xmalloc (sizeof (*cached_frame)
>> - + reg_count * sizeof (cached_frame->reg[0])));
>> + cached_frame = XNEW (cached_frame_info);
>
> but now you're not allocating enough space for the array elements...
>
>
>> cached_frame->gdbarch = gdbarch;
>> cached_frame->frame_id = unwind_info->frame_id;
>> cached_frame->reg_count = reg_count;
>> @@ -580,13 +568,14 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
>> struct value *value = value_object_to_value (reg->value);
>> size_t data_size = register_size (gdbarch, reg->number);
>>
>> - cached_frame->reg[i].number = reg->number;
>> + cached_frame->reg[i].num = reg->number;
>
> ... that you're accessing here and below.
>
> Valgrind probably shows the now-out-of-bounds accesses.
>
>
Ouch! My mistake.
Quick patch to revert that line to it’s previous state.
Ok?
2017-06-22 Alan Hayward <alan.hayward@arm.com>
* python/py-unwind.c (pyuw_sniffer): Allocate space for
registers.
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index da1703ecf2b843d9a6790f095e64c2915280ae35..1d800a7b7861da6a168440b600fb2862c42b4e4b 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -557,7 +557,10 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
saved_reg *reg;
int i;
- cached_frame = XNEW (cached_frame_info);
+ cached_frame
+ = ((cached_frame_info *)
+ xmalloc (sizeof (*cached_frame)
+ + reg_count * sizeof (cached_frame->reg[0])));
cached_frame->gdbarch = gdbarch;
cached_frame->frame_id = unwind_info->frame_id;
cached_frame->reg_count = reg_count;
next prev parent reply other threads:[~2017-06-22 14:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E4218BDE-2A92-490F-9443-27E25F4237C4@arm.com>
2017-06-21 9:30 ` Alan Hayward
2017-06-22 9:08 ` Yao Qi
2017-06-22 13:13 ` Alan Hayward
[not found] ` <8b641cf5-6cdc-5c4e-6f85-eb28f08bed9c@redhat.com>
2017-06-22 14:36 ` Alan Hayward [this message]
2017-06-22 15:25 ` 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=DE02AAD6-7EC8-4810-A605-0221ED6D350C@arm.com \
--to=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.com \
--cc=palves@redhat.com \
--cc=qiyaoltc@gmail.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