This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: extract_unsigned_integer API (Re: [PATCH] Remove MAX_REGISTER_SIZE from frame.c)
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: Alan Hayward <Alan dot Hayward at arm dot com>, "gdb-patches\@sourceware.org" <gdb-patches at sourceware dot org>, nd <nd at arm dot com>
- Date: Tue, 28 Mar 2017 17:13:08 +0100
- Subject: Re: extract_unsigned_integer API (Re: [PATCH] Remove MAX_REGISTER_SIZE from frame.c)
- Authentication-results: sourceware.org; auth=none
- References: <E80FFABA-2912-4223-AC55-2F4DE6055F47@arm.com> <86lgspqisk.fsf@gmail.com> <5f2f0cb0-6265-46aa-4ad6-eda5ba817da4@redhat.com>
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 (齐尧)