Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Pedro Alves <palves@redhat.com>
Cc: Alan Hayward <Alan.Hayward@arm.com>,
	 "gdb-patches\@sourceware.org" <gdb-patches@sourceware.org>,
	 nd <nd@arm.com>
Subject: Re: extract_unsigned_integer API (Re: [PATCH] Remove MAX_REGISTER_SIZE from frame.c)
Date: Tue, 28 Mar 2017 16:13:00 -0000	[thread overview]
Message-ID: <8660itnzvv.fsf@gmail.com> (raw)
In-Reply-To: <5f2f0cb0-6265-46aa-4ad6-eda5ba817da4@redhat.com> (Pedro Alves's	message of "Tue, 28 Mar 2017 15:08:51 +0100")

Pedro Alves <palves@redhat.com> writes:

> class extractor
> {
> public:
>    extractor () = default;
>
>    // Get buffer.  Could take a "size" parameter too,
>    // for pre-validation instead of passing "size" to "extract".
>    // Or make that a separate size() method.   Or add a "size" parameter
>    // to the ctor and validate there.  Whatever.  The lambda-based
>    // solution isn't validating upfront either.

My lambda-based solution does validate the boundary before reading
contents to buffer,

+ULONGEST
+extract_unsigned_integer (gdb::function_view<void (gdb_byte *, size_t size)> content_provider,
+                         int len, enum bfd_endian byte_order)
+{
+  if (len > (int) sizeof (ULONGEST))
+    error (_("\
+That operation is not available on integers of more than %d bytes."),
+          (int) sizeof (ULONGEST));
+
+  gdb_byte buf[sizeof (ULONGEST)];
+
+  content_provider (buf, len);
+  return extract_unsigned_integer_1 (buf, len, byte_order);
+}

>
>  extractor extr;
>  frame_unwind_register (frame, regnum, ext.buffer ());

We may overflow ext.buffer (), because the boundary checking is done in
.extract below,

>  return extr.extract (size, byte_order);
>
> Instead of:
>
>   return extract_unsigned_integer ([&] (gdb_byte *buf, size_t size)
> 				   {
> 				     frame_unwind_register (frame, regnum, buf);
> 				   }, size, byte_order);

-- 
Yao (齐尧)


  reply	other threads:[~2017-03-28 16:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 10:01 [PATCH] Remove MAX_REGISTER_SIZE from frame.c Alan Hayward
2017-03-01 12:32 ` Yao Qi
2017-03-24 14:49   ` Alan Hayward
2017-04-03 20:41     ` Yao Qi
2017-03-28 14:09   ` extract_unsigned_integer API (Re: [PATCH] Remove MAX_REGISTER_SIZE from frame.c) Pedro Alves
2017-03-28 16:13     ` Yao Qi [this message]
2017-03-28 16:57       ` Pedro Alves
2017-03-28 22:23         ` Pedro Alves
2017-04-03 13:58           ` Yao Qi
2017-04-04 11:01             ` Pedro Alves
2017-04-05 13:56               ` Yao Qi

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=8660itnzvv.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=Alan.Hayward@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=nd@arm.com \
    --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