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/amd64-tdep.c | |
parent | d9f82e931394efed68858eb7c7bb5832ad888482 (diff) | |
download | gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.zip gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.gz gdb-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/amd64-tdep.c')
-rw-r--r-- | gdb/amd64-tdep.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 4776120..e563d36 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -358,7 +358,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch, value *result_value = allocate_value (register_type (gdbarch, regnum)); VALUE_LVAL (result_value) = lval_register; VALUE_REGNUM (result_value) = regnum; - gdb_byte *buf = value_contents_raw (result_value); + gdb_byte *buf = value_contents_raw (result_value).data (); if (i386_byte_regnum_p (gdbarch, regnum)) { @@ -977,7 +977,7 @@ if (return_method == return_method_struct) else { /* The argument will be passed in registers. */ - const gdb_byte *valbuf = value_contents (args[i]); + const gdb_byte *valbuf = value_contents (args[i]).data (); gdb_byte buf[8]; gdb_assert (len <= 16); @@ -1029,7 +1029,7 @@ if (return_method == return_method_struct) for (i = 0; i < num_stack_args; i++) { struct type *type = value_type (stack_args[i]); - const gdb_byte *valbuf = value_contents (stack_args[i]); + const gdb_byte *valbuf = value_contents (stack_args[i]).data (); int len = TYPE_LENGTH (type); write_memory (sp + element * 8, valbuf, len); |