2017-12-10 22:00:49 +00:00
|
|
|
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
2017-12-04 19:24:00 +00:00
|
|
|
From: Fedora GDB patches <invalid@email.com>
|
|
|
|
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
2017-12-08 04:31:26 +00:00
|
|
|
Subject: Add a check to ensure that a type may fit into host memory
|
2012-11-09 18:03:10 +00:00
|
|
|
|
2017-12-04 19:24:00 +00:00
|
|
|
FileName: gdb-rhbz795424-bitpos-21of25.patch
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
;; Fix `GDB cannot access struct member whose offset is larger than 256MB'
|
|
|
|
;; (RH BZ 795424).
|
|
|
|
;;=push
|
2017-12-04 19:24:00 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
http://sourceware.org/ml/gdb-patches/2012-09/msg00632.html
|
2012-11-09 18:03:10 +00:00
|
|
|
|
|
|
|
--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
|
2017-12-08 04:31:26 +00:00
|
|
|
---
|
|
|
|
gdb/alpha-tdep.c | 7 +++++++
|
|
|
|
gdb/cp-valprint.c | 1 +
|
|
|
|
gdb/defs.h | 2 ++
|
|
|
|
gdb/p-valprint.c | 1 +
|
|
|
|
gdb/utils.c | 12 ++++++++++++
|
|
|
|
gdb/valops.c | 1 +
|
|
|
|
gdb/value.c | 4 ++++
|
|
|
|
gdb/vax-tdep.c | 1 +
|
|
|
|
8 files changed, 29 insertions(+)
|
2012-11-09 18:03:10 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
|
2017-12-18 17:28:39 +00:00
|
|
|
index 21199bd988..220dc58ef4 100644
|
2017-12-08 04:31:26 +00:00
|
|
|
--- a/gdb/alpha-tdep.c
|
|
|
|
+++ b/gdb/alpha-tdep.c
|
|
|
|
@@ -415,6 +415,13 @@ alpha_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
|
2012-11-09 18:03:10 +00:00
|
|
|
accumulate_size = 0;
|
|
|
|
else
|
|
|
|
accumulate_size -= sizeof(arg_reg_buffer);
|
|
|
|
+
|
|
|
|
+ /* Check for underflow. */
|
|
|
|
+ if (sp - accumulate_size > sp)
|
|
|
|
+ error (_("Insufficient memory in GDB host for arguments, "
|
|
|
|
+ "need %s bytes, but less than %s bytes available."),
|
|
|
|
+ plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp));
|
|
|
|
+
|
|
|
|
sp -= accumulate_size;
|
|
|
|
|
|
|
|
/* Keep sp aligned to a multiple of 16 as the ABI requires. */
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
|
|
|
|
index 38beb4d62a..bcb59507bd 100644
|
|
|
|
--- a/gdb/cp-valprint.c
|
|
|
|
+++ b/gdb/cp-valprint.c
|
|
|
|
@@ -529,6 +529,7 @@ cp_print_value (struct type *type, struct type *real_type,
|
|
|
|
if ((boffset + offset) < 0
|
|
|
|
|| (boffset + offset) >= TYPE_LENGTH (real_type))
|
|
|
|
{
|
2012-11-09 18:03:10 +00:00
|
|
|
+ ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
|
2017-12-08 04:31:26 +00:00
|
|
|
gdb::byte_vector buf (TYPE_LENGTH (baseclass));
|
2012-11-09 18:03:10 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
if (target_read_memory (address + boffset, buf.data (),
|
|
|
|
diff --git a/gdb/defs.h b/gdb/defs.h
|
|
|
|
index f76293fedf..27f3becab0 100644
|
|
|
|
--- a/gdb/defs.h
|
|
|
|
+++ b/gdb/defs.h
|
|
|
|
@@ -705,4 +705,6 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
|
2012-11-09 18:03:10 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
#include "utils.h"
|
2012-11-09 18:03:10 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
+extern void ulongest_fits_host_or_error (ULONGEST num);
|
|
|
|
+
|
|
|
|
#endif /* #ifndef DEFS_H */
|
|
|
|
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
|
|
|
|
index 3cdc847fe3..8d5b395afd 100644
|
|
|
|
--- a/gdb/p-valprint.c
|
|
|
|
+++ b/gdb/p-valprint.c
|
|
|
|
@@ -771,6 +771,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
|
|
|
|
|
|
|
|
if (boffset < 0 || boffset >= TYPE_LENGTH (type))
|
|
|
|
{
|
2012-11-09 18:03:10 +00:00
|
|
|
+ ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
|
2017-12-08 04:31:26 +00:00
|
|
|
buf.resize (TYPE_LENGTH (baseclass));
|
2012-11-09 18:03:10 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
base_valaddr = buf.data ();
|
|
|
|
diff --git a/gdb/utils.c b/gdb/utils.c
|
2017-12-18 17:28:39 +00:00
|
|
|
index c306e0c384..a0c7e9b03a 100644
|
2017-12-08 04:31:26 +00:00
|
|
|
--- a/gdb/utils.c
|
|
|
|
+++ b/gdb/utils.c
|
2017-12-18 17:28:39 +00:00
|
|
|
@@ -2836,6 +2836,18 @@ string_to_core_addr (const char *my_string)
|
2014-06-19 20:14:32 +00:00
|
|
|
return addr;
|
2012-11-09 18:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+/* Ensure that the input NUM is not larger than the maximum capacity of the
|
|
|
|
+ host system. We choose SIZE_MAX / 8 as a conservative estimate of the size
|
|
|
|
+ of a resource that a system may allocate. */
|
|
|
|
+void
|
|
|
|
+ulongest_fits_host_or_error (ULONGEST num)
|
|
|
|
+{
|
|
|
|
+ if (num > SIZE_MAX / 8)
|
|
|
|
+ error (_("Insufficient memory in host GDB for object of size %s bytes, "
|
|
|
|
+ "maximum allowed %s bytes."), pulongest (num),
|
|
|
|
+ pulongest (SIZE_MAX / 8));
|
|
|
|
+}
|
|
|
|
+
|
2017-12-08 04:31:26 +00:00
|
|
|
gdb::unique_xmalloc_ptr<char>
|
2012-11-09 18:03:10 +00:00
|
|
|
gdb_realpath (const char *filename)
|
|
|
|
{
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/valops.c b/gdb/valops.c
|
|
|
|
index a7c3613d84..eebcb8e5e1 100644
|
|
|
|
--- a/gdb/valops.c
|
|
|
|
+++ b/gdb/valops.c
|
|
|
|
@@ -2087,6 +2087,7 @@ search_struct_method (const char *name, struct value **arg1p,
|
|
|
|
{
|
2012-11-09 18:03:10 +00:00
|
|
|
CORE_ADDR address;
|
|
|
|
|
|
|
|
+ ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
|
2017-12-08 04:31:26 +00:00
|
|
|
gdb::byte_vector tmp (TYPE_LENGTH (baseclass));
|
2012-11-09 18:03:10 +00:00
|
|
|
address = value_address (*arg1p);
|
2017-12-08 04:31:26 +00:00
|
|
|
|
|
|
|
diff --git a/gdb/value.c b/gdb/value.c
|
|
|
|
index 0c87ae75ee..105c28bea7 100644
|
|
|
|
--- a/gdb/value.c
|
|
|
|
+++ b/gdb/value.c
|
|
|
|
@@ -926,6 +926,7 @@ allocate_value_lazy (struct type *type)
|
2012-11-09 18:03:10 +00:00
|
|
|
description correctly. */
|
|
|
|
check_typedef (type);
|
|
|
|
|
|
|
|
+ ulongest_fits_host_or_error (TYPE_LENGTH (type));
|
2015-11-03 21:28:36 +00:00
|
|
|
val = XCNEW (struct value);
|
2012-11-09 18:03:10 +00:00
|
|
|
val->contents = NULL;
|
|
|
|
val->next = all_values;
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -1023,6 +1024,8 @@ check_type_length_before_alloc (const struct type *type)
|
2014-02-07 18:38:14 +00:00
|
|
|
static void
|
2012-11-09 18:03:10 +00:00
|
|
|
allocate_value_contents (struct value *val)
|
|
|
|
{
|
|
|
|
+ ulongest_fits_host_or_error (TYPE_LENGTH (val->enclosing_type));
|
|
|
|
+
|
|
|
|
if (!val->contents)
|
2016-02-13 21:53:22 +00:00
|
|
|
{
|
|
|
|
check_type_length_before_alloc (val->enclosing_type);
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -3015,6 +3018,7 @@ set_value_enclosing_type (struct value *val, struct type *new_encl_type)
|
2016-02-13 21:53:22 +00:00
|
|
|
if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val)))
|
|
|
|
{
|
|
|
|
check_type_length_before_alloc (new_encl_type);
|
2012-11-09 18:03:10 +00:00
|
|
|
+ ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
|
2016-02-13 21:53:22 +00:00
|
|
|
val->contents
|
|
|
|
= (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
|
|
|
|
}
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/vax-tdep.c b/gdb/vax-tdep.c
|
|
|
|
index c1f10c8b65..f31acc8f01 100644
|
|
|
|
--- a/gdb/vax-tdep.c
|
|
|
|
+++ b/gdb/vax-tdep.c
|
|
|
|
@@ -218,6 +218,7 @@ vax_return_value (struct gdbarch *gdbarch, struct value *function,
|
2012-11-09 18:03:10 +00:00
|
|
|
ULONGEST addr;
|
|
|
|
|
|
|
|
regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
|
|
|
|
+ ulongest_fits_host_or_error (TYPE_LENGTH (type));
|
2013-01-19 22:41:55 +00:00
|
|
|
read_memory (addr, readbuf, len);
|
2012-11-09 18:03:10 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
--
|
|
|
|
2.14.3
|
|
|
|
|