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

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