Skip to content

Commit 6024f4b

Browse files
ivanivanov884jeffmahoney
authored andcommitted
gdb-rhbz795424-bitpos-21of25.patch
;; Fix `GDB cannot access struct member whose offset is larger than 256MB' ;; (RH BZ 795424). ;;=push http://sourceware.org/ml/gdb-patches/2012-09/msg00632.html --MP_/PnL6l3LUsXWpZ/olqawWlzb Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, This is part two of the bitpos expansion patch. This implements checks in some places in the code to ensure that a type size in ULONGEST is small enough to fit into host memory. Tested for regressions on x86_64 Fedora 16. Regards, Siddhesh --MP_/PnL6l3LUsXWpZ/olqawWlzb Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=ChangeLog-ensure_sizet gdb/ChangeLog * alpha-tdep.c (alpha_push_dummy_call) Check for underflow in SP. * cp-valprint (cp_print_value): Ensure BASECLASS fits into size_t. * dwarf2loc.c (read_pieced_value): Ensure that THIS_SIZE fits into size_t. (write_pieced_value): Likewise. * findcmd.c (parse_find_args): Ensure PATTERN_BUF_SIZE fits into size_t. * p-valprint (pascal_object_print_value): Ensure BASECLASS fits into size_t. * utils.c (ulongest_fits_host_or_error): New function to find if a ULONGEST number fits into size_t. * utils.h: Declare ulongest_fits_host_or_error. * valops.c (search_struct_method): Ensure BASECLASS fits into size_t. * value.c (allocate_value_lazy): Ensure TYPE fits into size_t. (allocate_value_contents): Likewise. (set_value_enclosing_type): Ensure NEW_ENCL_TYPE fits into size_t. * vax-tdep.c (vax_return_value): Ensure that TYPE fits into size_t. --MP_/PnL6l3LUsXWpZ/olqawWlzb Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=bitpos-ensure-size_t.patch
1 parent d04183a commit 6024f4b

8 files changed

Lines changed: 28 additions & 0 deletions

File tree

gdb/alpha-tdep.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ alpha_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
413413
accumulate_size = 0;
414414
else
415415
accumulate_size -= sizeof(arg_reg_buffer);
416+
417+
/* Check for underflow. */
418+
if (sp - accumulate_size > sp)
419+
error (_("Insufficient memory in GDB host for arguments, "
420+
"need %s bytes, but less than %s bytes available."),
421+
plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp));
422+
416423
sp -= accumulate_size;
417424

418425
/* Keep sp aligned to a multiple of 16 as the ABI requires. */

gdb/cp-valprint.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ cp_print_value (struct type *type, struct type *real_type,
529529
if ((boffset + offset) < 0
530530
|| (boffset + offset) >= TYPE_LENGTH (real_type))
531531
{
532+
ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
532533
gdb::byte_vector buf (TYPE_LENGTH (baseclass));
533534

534535
if (target_read_memory (address + boffset, buf.data (),

gdb/defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,6 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
665665

666666
#include "utils.h"
667667

668+
extern void ulongest_fits_host_or_error (ULONGEST num);
669+
668670
#endif /* #ifndef DEFS_H */

gdb/p-valprint.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
773773

774774
if (boffset < 0 || boffset >= TYPE_LENGTH (type))
775775
{
776+
ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
776777
buf.resize (TYPE_LENGTH (baseclass));
777778

778779
base_valaddr = buf.data ();

gdb/utils.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,17 @@ string_to_core_addr (const char *my_string)
28342834
return addr;
28352835
}
28362836

2837+
/* Ensure that the input NUM is not larger than the maximum capacity of the
2838+
host system. We choose SIZE_MAX / 8 as a conservative estimate of the size
2839+
of a resource that a system may allocate. */
2840+
void
2841+
ulongest_fits_host_or_error (ULONGEST num)
2842+
{
2843+
if (num > SIZE_MAX / 8)
2844+
error (_("Insufficient memory in host GDB for object of size %s bytes, "
2845+
"maximum allowed %s bytes."), pulongest (num),
2846+
pulongest (SIZE_MAX / 8));
2847+
}
28372848
#if GDB_SELF_TEST
28382849

28392850
static void

gdb/valops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,7 @@ search_struct_method (const char *name, struct value **arg1p,
20882088
{
20892089
CORE_ADDR address;
20902090

2091+
ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
20912092
gdb::byte_vector tmp (TYPE_LENGTH (baseclass));
20922093
address = value_address (*arg1p);
20932094

gdb/value.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ allocate_value_lazy (struct type *type)
933933
description correctly. */
934934
check_typedef (type);
935935

936+
ulongest_fits_host_or_error (TYPE_LENGTH (type));
936937
val = new struct value (type);
937938

938939
/* Values start out on the all_values chain. */
@@ -1015,6 +1016,8 @@ check_type_length_before_alloc (const struct type *type)
10151016
static void
10161017
allocate_value_contents (struct value *val)
10171018
{
1019+
ulongest_fits_host_or_error (TYPE_LENGTH (val->enclosing_type));
1020+
10181021
if (!val->contents)
10191022
{
10201023
check_type_length_before_alloc (val->enclosing_type);
@@ -2876,6 +2879,7 @@ set_value_enclosing_type (struct value *val, struct type *new_encl_type)
28762879
if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val)))
28772880
{
28782881
check_type_length_before_alloc (new_encl_type);
2882+
ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
28792883
val->contents
28802884
.reset ((gdb_byte *) xrealloc (val->contents.release (),
28812885
TYPE_LENGTH (new_encl_type)));

gdb/vax-tdep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ vax_return_value (struct gdbarch *gdbarch, struct value *function,
218218
ULONGEST addr;
219219

220220
regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
221+
ulongest_fits_host_or_error (TYPE_LENGTH (type));
221222
read_memory (addr, readbuf, len);
222223
}
223224

0 commit comments

Comments
 (0)