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

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