Blame SOURCES/gdb-rhbz795424-bitpos-21of25.patch

190f2a
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
190f2a
From: Fedora GDB patches <invalid@email.com>
190f2a
Date: Fri, 27 Oct 2017 21:07:50 +0200
190f2a
Subject: gdb-rhbz795424-bitpos-21of25.patch
190f2a
190f2a
;; Fix `GDB cannot access struct member whose offset is larger than 256MB'
190f2a
;; (RH BZ 795424).
190f2a
;;=push
190f2a
190f2a
http://sourceware.org/ml/gdb-patches/2012-09/msg00632.html
190f2a
190f2a
--MP_/PnL6l3LUsXWpZ/olqawWlzb
190f2a
Content-Type: text/plain; charset=US-ASCII
190f2a
Content-Transfer-Encoding: 7bit
190f2a
Content-Disposition: inline
190f2a
190f2a
Hi,
190f2a
190f2a
This is part two of the bitpos expansion patch.  This implements checks
190f2a
in some places in the code to ensure that a type size in ULONGEST is
190f2a
small enough to fit into host memory.  Tested for regressions on x86_64
190f2a
Fedora 16.
190f2a
190f2a
Regards,
190f2a
Siddhesh
190f2a
190f2a
--MP_/PnL6l3LUsXWpZ/olqawWlzb
190f2a
Content-Type: text/plain
190f2a
Content-Transfer-Encoding: quoted-printable
190f2a
Content-Disposition: attachment; filename=ChangeLog-ensure_sizet
190f2a
190f2a
gdb/ChangeLog
190f2a
190f2a
	* alpha-tdep.c (alpha_push_dummy_call) Check for underflow in
190f2a
	SP.
190f2a
	* cp-valprint (cp_print_value): Ensure BASECLASS fits into
190f2a
	size_t.
190f2a
	* dwarf2loc.c (read_pieced_value): Ensure that THIS_SIZE fits
190f2a
	into size_t.
190f2a
	(write_pieced_value): Likewise.
190f2a
	* findcmd.c (parse_find_args): Ensure PATTERN_BUF_SIZE fits into
190f2a
	size_t.
190f2a
	* p-valprint (pascal_object_print_value): Ensure BASECLASS fits
190f2a
	into size_t.
190f2a
	* utils.c (ulongest_fits_host_or_error): New function to find if
190f2a
	a ULONGEST number fits into size_t.
190f2a
	* utils.h: Declare ulongest_fits_host_or_error.
190f2a
	* valops.c (search_struct_method): Ensure BASECLASS fits into
190f2a
	size_t.
190f2a
	* value.c (allocate_value_lazy): Ensure TYPE fits into size_t.
190f2a
	(allocate_value_contents): Likewise.
190f2a
	(set_value_enclosing_type): Ensure NEW_ENCL_TYPE fits into
190f2a
	size_t.
190f2a
	* vax-tdep.c (vax_return_value): Ensure that TYPE fits into
190f2a
	size_t.
190f2a
190f2a
--MP_/PnL6l3LUsXWpZ/olqawWlzb
190f2a
Content-Type: text/x-patch
190f2a
Content-Transfer-Encoding: 7bit
190f2a
Content-Disposition: attachment; filename=bitpos-ensure-size_t.patch
190f2a
190f2a
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
190f2a
--- a/gdb/alpha-tdep.c
190f2a
+++ b/gdb/alpha-tdep.c
190f2a
@@ -413,6 +413,13 @@ alpha_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
190f2a
     accumulate_size = 0;
190f2a
   else
190f2a
     accumulate_size -= sizeof(arg_reg_buffer);
190f2a
+
190f2a
+  /* Check for underflow.  */
190f2a
+  if (sp - accumulate_size > sp)
190f2a
+    error (_("Insufficient memory in GDB host for arguments, "
190f2a
+	     "need %s bytes, but less than %s bytes available."),
190f2a
+	   plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp));
190f2a
+
190f2a
   sp -= accumulate_size;
190f2a
 
190f2a
   /* Keep sp aligned to a multiple of 16 as the ABI requires.  */
190f2a
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
190f2a
--- a/gdb/cp-valprint.c
190f2a
+++ b/gdb/cp-valprint.c
190f2a
@@ -529,6 +529,7 @@ cp_print_value (struct type *type, struct type *real_type,
190f2a
 	      if ((boffset + offset) < 0
190f2a
 		  || (boffset + offset) >= TYPE_LENGTH (real_type))
190f2a
 		{
190f2a
+		  ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
190f2a
 		  gdb::byte_vector buf (TYPE_LENGTH (baseclass));
190f2a
 
190f2a
 		  if (target_read_memory (address + boffset, buf.data (),
190f2a
diff --git a/gdb/defs.h b/gdb/defs.h
190f2a
--- a/gdb/defs.h
190f2a
+++ b/gdb/defs.h
190f2a
@@ -665,4 +665,6 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
190f2a
 
190f2a
 #include "utils.h"
190f2a
 
190f2a
+extern void ulongest_fits_host_or_error (ULONGEST num);
190f2a
+
190f2a
 #endif /* #ifndef DEFS_H */
190f2a
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
190f2a
--- a/gdb/p-valprint.c
190f2a
+++ b/gdb/p-valprint.c
190f2a
@@ -773,6 +773,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
190f2a
 
190f2a
 	  if (boffset < 0 || boffset >= TYPE_LENGTH (type))
190f2a
 	    {
190f2a
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
190f2a
 	      buf.resize (TYPE_LENGTH (baseclass));
190f2a
 
190f2a
 	      base_valaddr = buf.data ();
190f2a
diff --git a/gdb/utils.c b/gdb/utils.c
190f2a
--- a/gdb/utils.c
190f2a
+++ b/gdb/utils.c
190f2a
@@ -2834,6 +2834,17 @@ string_to_core_addr (const char *my_string)
190f2a
   return addr;
190f2a
 }
190f2a
 
190f2a
+/* Ensure that the input NUM is not larger than the maximum capacity of the
190f2a
+   host system.  We choose SIZE_MAX / 8 as a conservative estimate of the size
190f2a
+   of a resource that a system may allocate.  */
190f2a
+void
190f2a
+ulongest_fits_host_or_error (ULONGEST num)
190f2a
+{
190f2a
+  if (num > SIZE_MAX / 8)
190f2a
+    error (_("Insufficient memory in host GDB for object of size %s bytes, "
190f2a
+	     "maximum allowed %s bytes."), pulongest (num),
190f2a
+	   pulongest (SIZE_MAX / 8));
190f2a
+}
190f2a
 #if GDB_SELF_TEST
190f2a
 
190f2a
 static void
190f2a
diff --git a/gdb/valops.c b/gdb/valops.c
190f2a
--- a/gdb/valops.c
190f2a
+++ b/gdb/valops.c
190f2a
@@ -2088,6 +2088,7 @@ search_struct_method (const char *name, struct value **arg1p,
190f2a
 	    {
190f2a
 	      CORE_ADDR address;
190f2a
 
190f2a
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
190f2a
 	      gdb::byte_vector tmp (TYPE_LENGTH (baseclass));
190f2a
 	      address = value_address (*arg1p);
190f2a
 
190f2a
diff --git a/gdb/value.c b/gdb/value.c
190f2a
--- a/gdb/value.c
190f2a
+++ b/gdb/value.c
190f2a
@@ -933,6 +933,7 @@ allocate_value_lazy (struct type *type)
190f2a
      description correctly.  */
190f2a
   check_typedef (type);
190f2a
 
190f2a
+  ulongest_fits_host_or_error (TYPE_LENGTH (type));
190f2a
   val = new struct value (type);
190f2a
 
190f2a
   /* Values start out on the all_values chain.  */
190f2a
@@ -1015,6 +1016,8 @@ check_type_length_before_alloc (const struct type *type)
190f2a
 static void
190f2a
 allocate_value_contents (struct value *val)
190f2a
 {
190f2a
+  ulongest_fits_host_or_error (TYPE_LENGTH (val->enclosing_type));
190f2a
+
190f2a
   if (!val->contents)
190f2a
     {
190f2a
       check_type_length_before_alloc (val->enclosing_type);
190f2a
@@ -2876,6 +2879,7 @@ set_value_enclosing_type (struct value *val, struct type *new_encl_type)
190f2a
   if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val)))
190f2a
     {
190f2a
       check_type_length_before_alloc (new_encl_type);
190f2a
+      ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
190f2a
       val->contents
190f2a
 	.reset ((gdb_byte *) xrealloc (val->contents.release (),
190f2a
 				       TYPE_LENGTH (new_encl_type)));
190f2a
diff --git a/gdb/vax-tdep.c b/gdb/vax-tdep.c
190f2a
--- a/gdb/vax-tdep.c
190f2a
+++ b/gdb/vax-tdep.c
190f2a
@@ -218,6 +218,7 @@ vax_return_value (struct gdbarch *gdbarch, struct value *function,
190f2a
 	  ULONGEST addr;
190f2a
 
190f2a
 	  regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
190f2a
+	  ulongest_fits_host_or_error (TYPE_LENGTH (type));
190f2a
 	  read_memory (addr, readbuf, len);
190f2a
 	}
190f2a