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

861f93
http://sourceware.org/ml/gdb-patches/2012-09/msg00632.html
861f93
Subject: [PATCH 2/4] Add a check to ensure that a type may fit into host memory
861f93
861f93
861f93
--MP_/PnL6l3LUsXWpZ/olqawWlzb
861f93
Content-Type: text/plain; charset=US-ASCII
861f93
Content-Transfer-Encoding: 7bit
861f93
Content-Disposition: inline
861f93
861f93
Hi,
861f93
861f93
This is part two of the bitpos expansion patch.  This implements checks
861f93
in some places in the code to ensure that a type size in ULONGEST is
861f93
small enough to fit into host memory.  Tested for regressions on x86_64
861f93
Fedora 16.
861f93
861f93
Regards,
861f93
Siddhesh
861f93
861f93
--MP_/PnL6l3LUsXWpZ/olqawWlzb
861f93
Content-Type: text/plain
861f93
Content-Transfer-Encoding: quoted-printable
861f93
Content-Disposition: attachment; filename=ChangeLog-ensure_sizet
861f93
861f93
gdb/ChangeLog
861f93
861f93
	* alpha-tdep.c (alpha_push_dummy_call) Check for underflow in
861f93
	SP.
861f93
	* cp-valprint (cp_print_value): Ensure BASECLASS fits into
861f93
	size_t.
861f93
	* dwarf2loc.c (read_pieced_value): Ensure that THIS_SIZE fits
861f93
	into size_t.
861f93
	(write_pieced_value): Likewise.
861f93
	* findcmd.c (parse_find_args): Ensure PATTERN_BUF_SIZE fits into
861f93
	size_t.
861f93
	* p-valprint (pascal_object_print_value): Ensure BASECLASS fits
861f93
	into size_t.
861f93
	* utils.c (ulongest_fits_host_or_error): New function to find if
861f93
	a ULONGEST number fits into size_t.
861f93
	* utils.h: Declare ulongest_fits_host_or_error.
861f93
	* valops.c (search_struct_method): Ensure BASECLASS fits into
861f93
	size_t.
861f93
	* value.c (allocate_value_lazy): Ensure TYPE fits into size_t.
861f93
	(allocate_value_contents): Likewise.
861f93
	(set_value_enclosing_type): Ensure NEW_ENCL_TYPE fits into
861f93
	size_t.
861f93
	* vax-tdep.c (vax_return_value): Ensure that TYPE fits into
861f93
	size_t.
861f93
861f93
--MP_/PnL6l3LUsXWpZ/olqawWlzb
861f93
Content-Type: text/x-patch
861f93
Content-Transfer-Encoding: 7bit
861f93
Content-Disposition: attachment; filename=bitpos-ensure-size_t.patch
861f93
861f93
Index: gdb-7.5.50.20130118/gdb/alpha-tdep.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/alpha-tdep.c	2013-01-18 23:33:59.277047324 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/alpha-tdep.c	2013-01-18 23:34:02.678051846 +0100
861f93
@@ -414,6 +414,13 @@ alpha_push_dummy_call (struct gdbarch *g
861f93
     accumulate_size = 0;
861f93
   else
861f93
     accumulate_size -= sizeof(arg_reg_buffer);
861f93
+
861f93
+  /* Check for underflow.  */
861f93
+  if (sp - accumulate_size > sp)
861f93
+    error (_("Insufficient memory in GDB host for arguments, "
861f93
+	     "need %s bytes, but less than %s bytes available."),
861f93
+	   plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp));
861f93
+
861f93
   sp -= accumulate_size;
861f93
 
861f93
   /* Keep sp aligned to a multiple of 16 as the ABI requires.  */
861f93
Index: gdb-7.5.50.20130118/gdb/cp-valprint.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/cp-valprint.c	2013-01-18 23:33:59.278047326 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/cp-valprint.c	2013-01-18 23:34:02.679051848 +0100
861f93
@@ -540,6 +540,8 @@ cp_print_value (struct type *type, struc
861f93
 		  gdb_byte *buf;
861f93
 		  struct cleanup *back_to;
861f93
 
861f93
+		  ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
861f93
+
861f93
 		  buf = xmalloc (TYPE_LENGTH (baseclass));
861f93
 		  back_to = make_cleanup (xfree, buf);
861f93
 
861f93
Index: gdb-7.5.50.20130118/gdb/dwarf2loc.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/dwarf2loc.c	2013-01-18 23:33:59.280047332 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/dwarf2loc.c	2013-01-18 23:34:02.680051851 +0100
861f93
@@ -1784,6 +1784,8 @@ read_pieced_value (struct value *v)
861f93
 
861f93
       this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
861f93
       source_offset = source_offset_bits / 8;
861f93
+      ulongest_fits_host_or_error (this_size);
861f93
+
861f93
       if (buffer_size < this_size)
861f93
 	{
861f93
 	  buffer_size = this_size;
861f93
@@ -1975,6 +1977,7 @@ write_pieced_value (struct value *to, st
861f93
 	}
861f93
       else
861f93
 	{
861f93
+	  ulongest_fits_host_or_error (this_size);
861f93
 	  if (buffer_size < this_size)
861f93
 	    {
861f93
 	      buffer_size = this_size;
861f93
Index: gdb-7.5.50.20130118/gdb/findcmd.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/findcmd.c	2013-01-18 23:33:59.280047332 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/findcmd.c	2013-01-18 23:34:02.680051851 +0100
861f93
@@ -187,6 +187,7 @@ parse_find_args (char *args, ULONGEST *m
861f93
 	  size_t current_offset = pattern_buf_end - pattern_buf;
861f93
 
861f93
 	  pattern_buf_size = pattern_buf_size_need * 2;
861f93
+	  ulongest_fits_host_or_error (pattern_buf_size);
861f93
 	  pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
861f93
 	  pattern_buf_end = pattern_buf + current_offset;
861f93
 	}
861f93
Index: gdb-7.5.50.20130118/gdb/p-valprint.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/p-valprint.c	2013-01-18 23:33:59.281047334 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/p-valprint.c	2013-01-18 23:34:02.680051851 +0100
861f93
@@ -797,6 +797,7 @@ pascal_object_print_value (struct type *
861f93
 	      gdb_byte *buf;
861f93
 	      struct cleanup *back_to;
861f93
 
861f93
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
861f93
 	      buf = xmalloc (TYPE_LENGTH (baseclass));
861f93
 	      back_to = make_cleanup (xfree, buf);
861f93
 
861f93
Index: gdb-7.5.50.20130118/gdb/utils.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/utils.c	2013-01-18 23:33:59.282047336 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/utils.c	2013-01-18 23:34:02.681051854 +0100
861f93
@@ -3219,6 +3219,18 @@ host_address_to_string (const void *addr
861f93
   return str;
861f93
 }
861f93
 
861f93
+/* Ensure that the input NUM is not larger than the maximum capacity of the
861f93
+   host system.  We choose SIZE_MAX / 8 as a conservative estimate of the size
861f93
+   of a resource that a system may allocate.  */
861f93
+void
861f93
+ulongest_fits_host_or_error (ULONGEST num)
861f93
+{
861f93
+  if (num > SIZE_MAX / 8)
861f93
+    error (_("Insufficient memory in host GDB for object of size %s bytes, "
861f93
+	     "maximum allowed %s bytes."), pulongest (num),
861f93
+	   pulongest (SIZE_MAX / 8));
861f93
+}
861f93
+
861f93
 char *
861f93
 gdb_realpath (const char *filename)
861f93
 {
861f93
Index: gdb-7.5.50.20130118/gdb/valops.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/valops.c	2013-01-18 23:33:59.283047338 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/valops.c	2013-01-18 23:34:02.682051856 +0100
861f93
@@ -2369,6 +2369,7 @@ search_struct_method (const char *name,
861f93
 	      struct cleanup *back_to;
861f93
 	      CORE_ADDR address;
861f93
 
861f93
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
861f93
 	      tmp = xmalloc (TYPE_LENGTH (baseclass));
861f93
 	      back_to = make_cleanup (xfree, tmp);
861f93
 	      address = value_address (*arg1p);
861f93
Index: gdb-7.5.50.20130118/gdb/value.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/value.c	2013-01-18 23:33:59.285047342 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/value.c	2013-01-18 23:34:02.683051858 +0100
861f93
@@ -663,6 +663,7 @@ allocate_value_lazy (struct type *type)
861f93
      description correctly.  */
861f93
   check_typedef (type);
861f93
 
861f93
+  ulongest_fits_host_or_error (TYPE_LENGTH (type));
861f93
   val = (struct value *) xzalloc (sizeof (struct value));
861f93
   val->contents = NULL;
861f93
   val->next = all_values;
861f93
@@ -694,6 +695,8 @@ allocate_value_lazy (struct type *type)
861f93
 void
861f93
 allocate_value_contents (struct value *val)
861f93
 {
861f93
+  ulongest_fits_host_or_error (TYPE_LENGTH (val->enclosing_type));
861f93
+
861f93
   if (!val->contents)
861f93
     val->contents = (gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type));
861f93
 }
861f93
@@ -2672,8 +2675,12 @@ void
861f93
 set_value_enclosing_type (struct value *val, struct type *new_encl_type)
861f93
 {
861f93
   if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val))) 
861f93
-    val->contents =
861f93
-      (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
861f93
+    {
861f93
+      ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
861f93
+
861f93
+      val->contents =
861f93
+	(gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
861f93
+    }
861f93
 
861f93
   val->enclosing_type = new_encl_type;
861f93
 }
861f93
Index: gdb-7.5.50.20130118/gdb/vax-tdep.c
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/vax-tdep.c	2013-01-18 23:34:02.683051858 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/vax-tdep.c	2013-01-18 23:34:34.950094198 +0100
861f93
@@ -223,6 +223,7 @@ vax_return_value (struct gdbarch *gdbarc
861f93
 	  ULONGEST addr;
861f93
 
861f93
 	  regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
861f93
+	  ulongest_fits_host_or_error (TYPE_LENGTH (type));
861f93
 	  read_memory (addr, readbuf, len);
861f93
 	}
861f93
 
861f93
Index: gdb-7.5.50.20130118/gdb/defs.h
861f93
===================================================================
861f93
--- gdb-7.5.50.20130118.orig/gdb/defs.h	2013-01-18 23:34:02.684051860 +0100
861f93
+++ gdb-7.5.50.20130118/gdb/defs.h	2013-01-18 23:34:14.238067193 +0100
861f93
@@ -801,4 +801,6 @@ enum block_enum
861f93
 
861f93
 #include "utils.h"
861f93
 
861f93
+extern void ulongest_fits_host_or_error (ULONGEST num);
861f93
+
861f93
 #endif /* #ifndef DEFS_H */