diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-10-04 20:47:06 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-10-25 14:51:44 -0400 |
commit | 50888e42dcd32b30e1144c0aa6d1c1490da45cd9 (patch) | |
tree | 72fad89d67057ecb53f26bac0464542829053e3e /gdb/hppa-tdep.c | |
parent | d9f82e931394efed68858eb7c7bb5832ad888482 (diff) | |
download | binutils-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.zip binutils-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.gz binutils-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.bz2 |
gdb: change functions returning value contents to use gdb::array_view
The bug fixed by this [1] patch was caused by an out-of-bounds access to
a value's content. The code gets the value's content (just a pointer)
and then indexes it with a non-sensical index.
This made me think of changing functions that return value contents to
return array_views instead of a plain pointer. This has the advantage
that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view
are checked, making bugs more apparent / easier to find.
This patch changes the return types of these functions, and updates
callers to call .data() on the result, meaning it's not changing
anything in practice. Additional work will be needed (which can be done
little by little) to make callers propagate the use of array_view and
reap the benefits.
[1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html
Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
Diffstat (limited to 'gdb/hppa-tdep.c')
-rw-r--r-- | gdb/hppa-tdep.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c index db26195..344022c 100644 --- a/gdb/hppa-tdep.c +++ b/gdb/hppa-tdep.c @@ -758,8 +758,8 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, param_len = 4; struct_ptr += align_up (TYPE_LENGTH (type), 8); if (write_pass) - write_memory (struct_end - struct_ptr, value_contents (arg), - TYPE_LENGTH (type)); + write_memory (struct_end - struct_ptr, + value_contents (arg).data (), TYPE_LENGTH (type)); store_unsigned_integer (param_val, 4, byte_order, struct_end - struct_ptr); } @@ -769,15 +769,15 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* Integer value store, right aligned. "unpack_long" takes care of any sign-extension problems. */ param_len = align_up (TYPE_LENGTH (type), 4); - store_unsigned_integer (param_val, param_len, byte_order, - unpack_long (type, - value_contents (arg))); + store_unsigned_integer + (param_val, param_len, byte_order, + unpack_long (type, value_contents (arg).data ())); } else if (type->code () == TYPE_CODE_FLT) { /* Floating point value store, right aligned. */ param_len = align_up (TYPE_LENGTH (type), 4); - memcpy (param_val, value_contents (arg), param_len); + memcpy (param_val, value_contents (arg).data (), param_len); } else { @@ -785,7 +785,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* Small struct value are stored right-aligned. */ memcpy (param_val + param_len - TYPE_LENGTH (type), - value_contents (arg), TYPE_LENGTH (type)); + value_contents (arg).data (), TYPE_LENGTH (type)); /* Structures of size 5, 6 and 7 bytes are special in that the higher-ordered word is stored in the lower-ordered @@ -1041,7 +1041,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, the right halves of the floating point registers; the left halves are unused." */ regcache->cooked_write_part (regnum, offset % 8, len, - value_contents (arg)); + value_contents (arg).data ()); } } } @@ -1065,7 +1065,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, { ULONGEST codeptr, fptr; - codeptr = unpack_long (type, value_contents (arg)); + codeptr = unpack_long (type, value_contents (arg).data ()); fptr = hppa64_convert_code_addr_to_fptr (gdbarch, codeptr); store_unsigned_integer (fptrbuf, TYPE_LENGTH (type), byte_order, fptr); @@ -1073,7 +1073,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, } else { - valbuf = value_contents (arg); + valbuf = value_contents (arg).data (); } /* Always store the argument in memory. */ @@ -2769,7 +2769,7 @@ hppa_frame_prev_register_helper (struct frame_info *this_frame, trad_frame_get_prev_register (this_frame, saved_regs, HPPA_PCOQ_HEAD_REGNUM); - pc = extract_unsigned_integer (value_contents_all (pcoq_val), + pc = extract_unsigned_integer (value_contents_all (pcoq_val).data (), size, byte_order); return frame_unwind_got_constant (this_frame, regnum, pc + 4); } |