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/dwarf2/expr.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/dwarf2/expr.c')
-rw-r--r-- | gdb/dwarf2/expr.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 0f05f88..6521619 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -169,7 +169,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized) gdb_assert (!check_optimized || from == nullptr); if (from != nullptr) { - from_contents = value_contents (from); + from_contents = value_contents (from).data (); v_contents = nullptr; } else @@ -181,7 +181,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized) if (check_optimized) v_contents = nullptr; else - v_contents = value_contents_raw (v); + v_contents = value_contents_raw (v).data (); from_contents = nullptr; } @@ -394,7 +394,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized) bits_to_skip += p->offset; copy_bitwise (v_contents, offset, - value_contents_all (p->v.value), + value_contents_all (p->v.value).data (), bits_to_skip, this_size_bits, bits_big_endian); } @@ -577,7 +577,7 @@ indirect_pieced_value (value *value) encode address spaces and other things in CORE_ADDR. */ bfd_endian byte_order = gdbarch_byte_order (get_frame_arch (frame)); LONGEST byte_offset - = extract_signed_integer (value_contents (value), + = extract_signed_integer (value_contents (value).data (), TYPE_LENGTH (type), byte_order); byte_offset += piece->v.ptr.offset; @@ -1037,8 +1037,8 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG) subobj_offset += n - max; - memcpy (value_contents_raw (retval), - value_contents_all (val) + subobj_offset, len); + memcpy (value_contents_raw (retval).data (), + value_contents_all (val).data () + subobj_offset, len); } break; @@ -1050,7 +1050,7 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, invalid_synthetic_pointer (); retval = allocate_value (subobj_type); - bfd_byte *contents = value_contents_raw (retval); + bfd_byte *contents = value_contents_raw (retval).data (); memcpy (contents, this->m_data + subobj_offset, n); } break; @@ -1157,7 +1157,7 @@ dwarf_expr_context::fetch_address (int n) ULONGEST result; dwarf_require_integral (value_type (result_val)); - result = extract_unsigned_integer (value_contents (result_val), + result = extract_unsigned_integer (value_contents (result_val).data (), TYPE_LENGTH (value_type (result_val)), byte_order); @@ -2366,7 +2366,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr, else result_val = value_from_contents (type, - value_contents_all (result_val)); + value_contents_all (result_val).data ()); } break; |