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

7a6771
http://sourceware.org/ml/gdb-patches/2012-09/msg00632.html
7a6771
Subject: [PATCH 2/4] Add a check to ensure that a type may fit into host memory
7a6771
7a6771
7a6771
--MP_/PnL6l3LUsXWpZ/olqawWlzb
7a6771
Content-Type: text/plain; charset=US-ASCII
7a6771
Content-Transfer-Encoding: 7bit
7a6771
Content-Disposition: inline
7a6771
7a6771
Hi,
7a6771
7a6771
This is part two of the bitpos expansion patch.  This implements checks
7a6771
in some places in the code to ensure that a type size in ULONGEST is
7a6771
small enough to fit into host memory.  Tested for regressions on x86_64
7a6771
Fedora 16.
7a6771
7a6771
Regards,
7a6771
Siddhesh
7a6771
7a6771
--MP_/PnL6l3LUsXWpZ/olqawWlzb
7a6771
Content-Type: text/plain
7a6771
Content-Transfer-Encoding: quoted-printable
7a6771
Content-Disposition: attachment; filename=ChangeLog-ensure_sizet
7a6771
7a6771
gdb/ChangeLog
7a6771
7a6771
	* alpha-tdep.c (alpha_push_dummy_call) Check for underflow in
7a6771
	SP.
7a6771
	* cp-valprint (cp_print_value): Ensure BASECLASS fits into
7a6771
	size_t.
7a6771
	* dwarf2loc.c (read_pieced_value): Ensure that THIS_SIZE fits
7a6771
	into size_t.
7a6771
	(write_pieced_value): Likewise.
7a6771
	* findcmd.c (parse_find_args): Ensure PATTERN_BUF_SIZE fits into
7a6771
	size_t.
7a6771
	* p-valprint (pascal_object_print_value): Ensure BASECLASS fits
7a6771
	into size_t.
7a6771
	* utils.c (ulongest_fits_host_or_error): New function to find if
7a6771
	a ULONGEST number fits into size_t.
7a6771
	* utils.h: Declare ulongest_fits_host_or_error.
7a6771
	* valops.c (search_struct_method): Ensure BASECLASS fits into
7a6771
	size_t.
7a6771
	* value.c (allocate_value_lazy): Ensure TYPE fits into size_t.
7a6771
	(allocate_value_contents): Likewise.
7a6771
	(set_value_enclosing_type): Ensure NEW_ENCL_TYPE fits into
7a6771
	size_t.
7a6771
	* vax-tdep.c (vax_return_value): Ensure that TYPE fits into
7a6771
	size_t.
7a6771
7a6771
--MP_/PnL6l3LUsXWpZ/olqawWlzb
7a6771
Content-Type: text/x-patch
7a6771
Content-Transfer-Encoding: 7bit
7a6771
Content-Disposition: attachment; filename=bitpos-ensure-size_t.patch
7a6771
7a6771
Index: gdb-7.10.90.20160211/gdb/alpha-tdep.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/alpha-tdep.c	2016-02-11 20:56:59.224850729 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/alpha-tdep.c	2016-02-11 20:57:05.385891225 +0100
7a6771
@@ -413,6 +413,13 @@
7a6771
     accumulate_size = 0;
7a6771
   else
7a6771
     accumulate_size -= sizeof(arg_reg_buffer);
7a6771
+
7a6771
+  /* Check for underflow.  */
7a6771
+  if (sp - accumulate_size > sp)
7a6771
+    error (_("Insufficient memory in GDB host for arguments, "
7a6771
+	     "need %s bytes, but less than %s bytes available."),
7a6771
+	   plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp));
7a6771
+
7a6771
   sp -= accumulate_size;
7a6771
 
7a6771
   /* Keep sp aligned to a multiple of 16 as the ABI requires.  */
7a6771
Index: gdb-7.10.90.20160211/gdb/cp-valprint.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/cp-valprint.c	2016-02-11 20:56:59.224850729 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/cp-valprint.c	2016-02-11 20:57:05.385891225 +0100
7a6771
@@ -536,6 +536,8 @@
7a6771
 		  gdb_byte *buf;
7a6771
 		  struct cleanup *back_to;
7a6771
 
7a6771
+		  ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
7a6771
+
7a6771
 		  buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
7a6771
 		  back_to = make_cleanup (xfree, buf);
7a6771
 
7a6771
Index: gdb-7.10.90.20160211/gdb/dwarf2loc.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/dwarf2loc.c	2016-02-11 20:56:59.225850736 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/dwarf2loc.c	2016-02-11 20:57:05.386891231 +0100
7a6771
@@ -1744,6 +1744,8 @@
7a6771
 
7a6771
       this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
7a6771
       source_offset = source_offset_bits / 8;
7a6771
+      ulongest_fits_host_or_error (this_size);
7a6771
+
7a6771
       if (buffer_size < this_size)
7a6771
 	{
7a6771
 	  buffer_size = this_size;
7a6771
@@ -1926,6 +1928,7 @@
7a6771
 	}
7a6771
       else
7a6771
 	{
7a6771
+	  ulongest_fits_host_or_error (this_size);
7a6771
 	  if (buffer_size < this_size)
7a6771
 	    {
7a6771
 	      buffer_size = this_size;
7a6771
Index: gdb-7.10.90.20160211/gdb/findcmd.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/findcmd.c	2016-02-11 20:56:59.226850742 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/findcmd.c	2016-02-11 20:57:05.387891238 +0100
7a6771
@@ -184,6 +184,7 @@
7a6771
 	  size_t current_offset = pattern_buf_end - pattern_buf;
7a6771
 
7a6771
 	  pattern_buf_size = pattern_buf_size_need * 2;
7a6771
+	  ulongest_fits_host_or_error (pattern_buf_size);
7a6771
 	  pattern_buf = (gdb_byte *) xrealloc (pattern_buf, pattern_buf_size);
7a6771
 	  pattern_buf_end = pattern_buf + current_offset;
7a6771
 	}
7a6771
Index: gdb-7.10.90.20160211/gdb/p-valprint.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/p-valprint.c	2016-02-11 20:56:59.226850742 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/p-valprint.c	2016-02-11 20:57:05.387891238 +0100
7a6771
@@ -769,6 +769,7 @@
7a6771
 	      gdb_byte *buf;
7a6771
 	      struct cleanup *back_to;
7a6771
 
7a6771
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
7a6771
 	      buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
7a6771
 	      back_to = make_cleanup (xfree, buf);
7a6771
 
7a6771
Index: gdb-7.10.90.20160211/gdb/utils.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/utils.c	2016-02-11 20:56:59.227850749 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/utils.c	2016-02-11 20:57:05.388891244 +0100
7a6771
@@ -2837,6 +2837,18 @@
7a6771
   return addr;
7a6771
 }
7a6771
 
7a6771
+/* Ensure that the input NUM is not larger than the maximum capacity of the
7a6771
+   host system.  We choose SIZE_MAX / 8 as a conservative estimate of the size
7a6771
+   of a resource that a system may allocate.  */
7a6771
+void
7a6771
+ulongest_fits_host_or_error (ULONGEST num)
7a6771
+{
7a6771
+  if (num > SIZE_MAX / 8)
7a6771
+    error (_("Insufficient memory in host GDB for object of size %s bytes, "
7a6771
+	     "maximum allowed %s bytes."), pulongest (num),
7a6771
+	   pulongest (SIZE_MAX / 8));
7a6771
+}
7a6771
+
7a6771
 char *
7a6771
 gdb_realpath (const char *filename)
7a6771
 {
7a6771
Index: gdb-7.10.90.20160211/gdb/valops.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/valops.c	2016-02-11 20:56:59.228850755 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/valops.c	2016-02-11 20:57:05.389891251 +0100
7a6771
@@ -2057,6 +2057,7 @@
7a6771
 	      struct cleanup *back_to;
7a6771
 	      CORE_ADDR address;
7a6771
 
7a6771
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
7a6771
 	      tmp = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
7a6771
 	      back_to = make_cleanup (xfree, tmp);
7a6771
 	      address = value_address (*arg1p);
7a6771
Index: gdb-7.10.90.20160211/gdb/value.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/value.c	2016-02-11 20:56:59.229850762 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/value.c	2016-02-11 20:58:35.095480877 +0100
7a6771
@@ -935,6 +935,7 @@
7a6771
      description correctly.  */
7a6771
   check_typedef (type);
7a6771
 
7a6771
+  ulongest_fits_host_or_error (TYPE_LENGTH (type));
7a6771
   val = XCNEW (struct value);
7a6771
   val->contents = NULL;
7a6771
   val->next = all_values;
7a6771
@@ -1034,6 +1035,8 @@
7a6771
 static void
7a6771
 allocate_value_contents (struct value *val)
7a6771
 {
7a6771
+  ulongest_fits_host_or_error (TYPE_LENGTH (val->enclosing_type));
7a6771
+
7a6771
   if (!val->contents)
7a6771
     {
7a6771
       check_type_length_before_alloc (val->enclosing_type);
7a6771
@@ -3090,6 +3093,7 @@
7a6771
   if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val)))
7a6771
     {
7a6771
       check_type_length_before_alloc (new_encl_type);
7a6771
+      ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
7a6771
       val->contents
7a6771
 	= (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
7a6771
     }
7a6771
Index: gdb-7.10.90.20160211/gdb/vax-tdep.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/vax-tdep.c	2016-02-11 20:56:59.229850762 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/vax-tdep.c	2016-02-11 20:57:05.391891264 +0100
7a6771
@@ -219,6 +219,7 @@
7a6771
 	  ULONGEST addr;
7a6771
 
7a6771
 	  regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
7a6771
+	  ulongest_fits_host_or_error (TYPE_LENGTH (type));
7a6771
 	  read_memory (addr, readbuf, len);
7a6771
 	}
7a6771
 
7a6771
Index: gdb-7.10.90.20160211/gdb/defs.h
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/defs.h	2016-02-11 20:56:59.229850762 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/defs.h	2016-02-11 20:57:05.391891264 +0100
7a6771
@@ -690,4 +690,6 @@
7a6771
 
7a6771
 #include "utils.h"
7a6771
 
7a6771
+extern void ulongest_fits_host_or_error (ULONGEST num);
7a6771
+
7a6771
 #endif /* #ifndef DEFS_H */