diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-07-23 00:32:23 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-07-29 21:58:05 -0400 |
commit | 602885d8087f6ab35c8b9fd8ff0d5240a0b040a0 (patch) | |
tree | 14695ca2909e507b4049d586406ec9d9d8751996 | |
parent | bbf1c6a2370c86e3c43a3b6064f48473098e68aa (diff) | |
download | binutils-602885d8087f6ab35c8b9fd8ff0d5240a0b040a0.zip binutils-602885d8087f6ab35c8b9fd8ff0d5240a0b040a0.tar.gz binutils-602885d8087f6ab35c8b9fd8ff0d5240a0b040a0.tar.bz2 |
gdb: fix nr_bits gdb_assert in append_flags_type_field
The assertion
gdb_assert (nr_bits >= 1 && nr_bits <= type_bitsize);
is not correct. Well, it's correct in that we do want the number of
bits to be in the range [1, type_bitsize]. But we don't check anywhere
that the end of the specified flag is within the containing type.
The following code should generate a failed assertion, as the flag goes
past the 32 bits of the underlying type, but it's currently not caught:
static void
test_print_flag (gdbarch *arch)
{
type *flags_type = arch_flags_type (arch, "test_type", 32);
type *field_type = builtin_type (arch)->builtin_uint32;
append_flags_type_field (flags_type, 31, 2, field_type, "invalid");
}
(You can test this by registering it as a selftest using
selftests::register_test_foreach_arc and running.)
Change the assertion to verify that the end bit is within the range of
the underlying type. This implicitly verifies that nr_bits is not
too big as well, so we don't need a separate assertion for that.
Change-Id: I9be79e5fd7a5917bf25b03b598727e6274c892e8
Co-Authored-By: Tony Tye <Tony.Tye@amd.com>
-rw-r--r-- | gdb/gdbtypes.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index f76cafd..5ba0e8d 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -5839,7 +5839,7 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits, gdb_assert (type->code () == TYPE_CODE_FLAGS); gdb_assert (type->num_fields () + 1 <= type_bitsize); gdb_assert (start_bitpos >= 0 && start_bitpos < type_bitsize); - gdb_assert (nr_bits >= 1 && nr_bits <= type_bitsize); + gdb_assert (nr_bits >= 1 && (start_bitpos + nr_bits) <= type_bitsize); gdb_assert (name != NULL); TYPE_FIELD_NAME (type, field_nr) = xstrdup (name); |