Skip to content

Commit 2177dbb

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 ea84bd2 commit 2177dbb

File tree

8 files changed

+28
-0
lines changed

8 files changed

+28
-0
lines changed

gdb/alpha-tdep.c

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

419426
/* 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
@@ -531,6 +531,7 @@ cp_print_value (struct type *type, struct type *real_type,
531531
if ((boffset + offset) < 0
532532
|| (boffset + offset) >= TYPE_LENGTH (real_type))
533533
{
534+
ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
534535
gdb::byte_vector buf (TYPE_LENGTH (baseclass));
535536

536537
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
@@ -669,4 +669,6 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
669669

670670
#include "utils.h"
671671

672+
extern void ulongest_fits_host_or_error (ULONGEST num);
673+
672674
#endif /* #ifndef DEFS_H */

gdb/p-valprint.c

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

772772
if (boffset < 0 || boffset >= TYPE_LENGTH (type))
773773
{
774+
ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
774775
buf.resize (TYPE_LENGTH (baseclass));
775776

776777
base_valaddr = buf.data ();

gdb/utils.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,17 @@ string_to_core_addr (const char *my_string)
29282928
return addr;
29292929
}
29302930

2931+
/* Ensure that the input NUM is not larger than the maximum capacity of the
2932+
host system. We choose SIZE_MAX / 8 as a conservative estimate of the size
2933+
of a resource that a system may allocate. */
2934+
void
2935+
ulongest_fits_host_or_error (ULONGEST num)
2936+
{
2937+
if (num > SIZE_MAX / 8)
2938+
error (_("Insufficient memory in host GDB for object of size %s bytes, "
2939+
"maximum allowed %s bytes."), pulongest (num),
2940+
pulongest (SIZE_MAX / 8));
2941+
}
29312942
#if GDB_SELF_TEST
29322943

29332944
static void

gdb/valops.c

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

2067+
ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
20672068
gdb::byte_vector tmp (TYPE_LENGTH (baseclass));
20682069
address = value_address (*arg1p);
20692070

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);
@@ -2872,6 +2875,7 @@ set_value_enclosing_type (struct value *val, struct type *new_encl_type)
28722875
if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val)))
28732876
{
28742877
check_type_length_before_alloc (new_encl_type);
2878+
ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
28752879
val->contents
28762880
.reset ((gdb_byte *) xrealloc (val->contents.release (),
28772881
TYPE_LENGTH (new_encl_type)));

gdb/vax-tdep.c

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

221221
regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
222+
ulongest_fits_host_or_error (TYPE_LENGTH (type));
222223
read_memory (addr, readbuf, len);
223224
}
224225

0 commit comments

Comments
 (0)