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

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