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

f9426a
http://sourceware.org/ml/gdb-patches/2012-09/msg00632.html
f9426a
Subject: [PATCH 2/4] Add a check to ensure that a type may fit into host memory
f9426a
f9426a
f9426a
--MP_/PnL6l3LUsXWpZ/olqawWlzb
f9426a
Content-Type: text/plain; charset=US-ASCII
f9426a
Content-Transfer-Encoding: 7bit
f9426a
Content-Disposition: inline
f9426a
f9426a
Hi,
f9426a
f9426a
This is part two of the bitpos expansion patch.  This implements checks
f9426a
in some places in the code to ensure that a type size in ULONGEST is
f9426a
small enough to fit into host memory.  Tested for regressions on x86_64
f9426a
Fedora 16.
f9426a
f9426a
Regards,
f9426a
Siddhesh
f9426a
f9426a
--MP_/PnL6l3LUsXWpZ/olqawWlzb
f9426a
Content-Type: text/plain
f9426a
Content-Transfer-Encoding: quoted-printable
f9426a
Content-Disposition: attachment; filename=ChangeLog-ensure_sizet
f9426a
f9426a
gdb/ChangeLog
f9426a
f9426a
	* alpha-tdep.c (alpha_push_dummy_call) Check for underflow in
f9426a
	SP.
f9426a
	* cp-valprint (cp_print_value): Ensure BASECLASS fits into
f9426a
	size_t.
f9426a
	* dwarf2loc.c (read_pieced_value): Ensure that THIS_SIZE fits
f9426a
	into size_t.
f9426a
	(write_pieced_value): Likewise.
f9426a
	* findcmd.c (parse_find_args): Ensure PATTERN_BUF_SIZE fits into
f9426a
	size_t.
f9426a
	* p-valprint (pascal_object_print_value): Ensure BASECLASS fits
f9426a
	into size_t.
f9426a
	* utils.c (ulongest_fits_host_or_error): New function to find if
f9426a
	a ULONGEST number fits into size_t.
f9426a
	* utils.h: Declare ulongest_fits_host_or_error.
f9426a
	* valops.c (search_struct_method): Ensure BASECLASS fits into
f9426a
	size_t.
f9426a
	* value.c (allocate_value_lazy): Ensure TYPE fits into size_t.
f9426a
	(allocate_value_contents): Likewise.
f9426a
	(set_value_enclosing_type): Ensure NEW_ENCL_TYPE fits into
f9426a
	size_t.
f9426a
	* vax-tdep.c (vax_return_value): Ensure that TYPE fits into
f9426a
	size_t.
f9426a
f9426a
--MP_/PnL6l3LUsXWpZ/olqawWlzb
f9426a
Content-Type: text/x-patch
f9426a
Content-Transfer-Encoding: 7bit
f9426a
Content-Disposition: attachment; filename=bitpos-ensure-size_t.patch
f9426a
f9426a
Index: gdb-7.7.90.20140613/gdb/alpha-tdep.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/alpha-tdep.c	2014-06-13 22:14:49.725846383 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/alpha-tdep.c	2014-06-13 22:14:53.163850081 +0200
f9426a
@@ -414,6 +414,13 @@ alpha_push_dummy_call (struct gdbarch *g
f9426a
     accumulate_size = 0;
f9426a
   else
f9426a
     accumulate_size -= sizeof(arg_reg_buffer);
f9426a
+
f9426a
+  /* Check for underflow.  */
f9426a
+  if (sp - accumulate_size > sp)
f9426a
+    error (_("Insufficient memory in GDB host for arguments, "
f9426a
+	     "need %s bytes, but less than %s bytes available."),
f9426a
+	   plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp));
f9426a
+
f9426a
   sp -= accumulate_size;
f9426a
 
f9426a
   /* Keep sp aligned to a multiple of 16 as the ABI requires.  */
f9426a
Index: gdb-7.7.90.20140613/gdb/cp-valprint.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/cp-valprint.c	2014-06-13 22:14:49.725846383 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/cp-valprint.c	2014-06-13 22:14:53.164850081 +0200
f9426a
@@ -538,6 +538,8 @@ cp_print_value (struct type *type, struc
f9426a
 		  gdb_byte *buf;
f9426a
 		  struct cleanup *back_to;
f9426a
 
f9426a
+		  ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
f9426a
+
f9426a
 		  buf = xmalloc (TYPE_LENGTH (baseclass));
f9426a
 		  back_to = make_cleanup (xfree, buf);
f9426a
 
f9426a
Index: gdb-7.7.90.20140613/gdb/dwarf2loc.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/dwarf2loc.c	2014-06-13 22:14:49.726846384 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/dwarf2loc.c	2014-06-13 22:14:53.166850084 +0200
f9426a
@@ -1666,6 +1666,8 @@ read_pieced_value (struct value *v)
f9426a
 
f9426a
       this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
f9426a
       source_offset = source_offset_bits / 8;
f9426a
+      ulongest_fits_host_or_error (this_size);
f9426a
+
f9426a
       if (buffer_size < this_size)
f9426a
 	{
f9426a
 	  buffer_size = this_size;
f9426a
@@ -1857,6 +1859,7 @@ write_pieced_value (struct value *to, st
f9426a
 	}
f9426a
       else
f9426a
 	{
f9426a
+	  ulongest_fits_host_or_error (this_size);
f9426a
 	  if (buffer_size < this_size)
f9426a
 	    {
f9426a
 	      buffer_size = this_size;
f9426a
Index: gdb-7.7.90.20140613/gdb/findcmd.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/findcmd.c	2014-06-13 22:14:49.726846384 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/findcmd.c	2014-06-13 22:14:53.166850084 +0200
f9426a
@@ -185,6 +185,7 @@ parse_find_args (char *args, ULONGEST *m
f9426a
 	  size_t current_offset = pattern_buf_end - pattern_buf;
f9426a
 
f9426a
 	  pattern_buf_size = pattern_buf_size_need * 2;
f9426a
+	  ulongest_fits_host_or_error (pattern_buf_size);
f9426a
 	  pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
f9426a
 	  pattern_buf_end = pattern_buf + current_offset;
f9426a
 	}
f9426a
Index: gdb-7.7.90.20140613/gdb/p-valprint.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/p-valprint.c	2014-06-13 22:14:49.728846387 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/p-valprint.c	2014-06-13 22:14:53.166850084 +0200
f9426a
@@ -772,6 +772,7 @@ pascal_object_print_value (struct type *
f9426a
 	      gdb_byte *buf;
f9426a
 	      struct cleanup *back_to;
f9426a
 
f9426a
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
f9426a
 	      buf = xmalloc (TYPE_LENGTH (baseclass));
f9426a
 	      back_to = make_cleanup (xfree, buf);
f9426a
 
f9426a
Index: gdb-7.7.90.20140613/gdb/utils.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/utils.c	2014-06-13 22:14:53.166850084 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/utils.c	2014-06-13 22:15:16.839875341 +0200
f9426a
@@ -2838,6 +2838,18 @@ string_to_core_addr (const char *my_stri
f9426a
   return addr;
f9426a
 }
f9426a
 
f9426a
+/* Ensure that the input NUM is not larger than the maximum capacity of the
f9426a
+   host system.  We choose SIZE_MAX / 8 as a conservative estimate of the size
f9426a
+   of a resource that a system may allocate.  */
f9426a
+void
f9426a
+ulongest_fits_host_or_error (ULONGEST num)
f9426a
+{
f9426a
+  if (num > SIZE_MAX / 8)
f9426a
+    error (_("Insufficient memory in host GDB for object of size %s bytes, "
f9426a
+	     "maximum allowed %s bytes."), pulongest (num),
f9426a
+	   pulongest (SIZE_MAX / 8));
f9426a
+}
f9426a
+
f9426a
 char *
f9426a
 gdb_realpath (const char *filename)
f9426a
 {
f9426a
Index: gdb-7.7.90.20140613/gdb/valops.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/valops.c	2014-06-13 22:14:49.730846389 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/valops.c	2014-06-13 22:14:53.169850088 +0200
f9426a
@@ -2074,6 +2074,7 @@ search_struct_method (const char *name,
f9426a
 	      struct cleanup *back_to;
f9426a
 	      CORE_ADDR address;
f9426a
 
f9426a
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
f9426a
 	      tmp = xmalloc (TYPE_LENGTH (baseclass));
f9426a
 	      back_to = make_cleanup (xfree, tmp);
f9426a
 	      address = value_address (*arg1p);
f9426a
Index: gdb-7.7.90.20140613/gdb/value.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/value.c	2014-06-13 22:14:49.732846391 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/value.c	2014-06-13 22:14:53.169850088 +0200
f9426a
@@ -824,6 +824,7 @@ allocate_value_lazy (struct type *type)
f9426a
      description correctly.  */
f9426a
   check_typedef (type);
f9426a
 
f9426a
+  ulongest_fits_host_or_error (TYPE_LENGTH (type));
f9426a
   val = (struct value *) xzalloc (sizeof (struct value));
f9426a
   val->contents = NULL;
f9426a
   val->next = all_values;
f9426a
@@ -855,6 +856,8 @@ allocate_value_lazy (struct type *type)
f9426a
 static void
f9426a
 allocate_value_contents (struct value *val)
f9426a
 {
f9426a
+  ulongest_fits_host_or_error (TYPE_LENGTH (val->enclosing_type));
f9426a
+
f9426a
   if (!val->contents)
f9426a
     val->contents = (gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type));
f9426a
 }
f9426a
@@ -2831,8 +2834,12 @@ void
f9426a
 set_value_enclosing_type (struct value *val, struct type *new_encl_type)
f9426a
 {
f9426a
   if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val))) 
f9426a
-    val->contents =
f9426a
-      (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
f9426a
+    {
f9426a
+      ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
f9426a
+
f9426a
+      val->contents =
f9426a
+	(gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
f9426a
+    }
f9426a
 
f9426a
   val->enclosing_type = new_encl_type;
f9426a
 }
f9426a
Index: gdb-7.7.90.20140613/gdb/vax-tdep.c
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/vax-tdep.c	2014-06-13 22:14:49.732846391 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/vax-tdep.c	2014-06-13 22:14:53.169850088 +0200
f9426a
@@ -223,6 +223,7 @@ vax_return_value (struct gdbarch *gdbarc
f9426a
 	  ULONGEST addr;
f9426a
 
f9426a
 	  regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
f9426a
+	  ulongest_fits_host_or_error (TYPE_LENGTH (type));
f9426a
 	  read_memory (addr, readbuf, len);
f9426a
 	}
f9426a
 
f9426a
Index: gdb-7.7.90.20140613/gdb/defs.h
f9426a
===================================================================
f9426a
--- gdb-7.7.90.20140613.orig/gdb/defs.h	2014-06-13 22:14:49.732846391 +0200
f9426a
+++ gdb-7.7.90.20140613/gdb/defs.h	2014-06-13 22:14:53.169850088 +0200
f9426a
@@ -756,4 +756,6 @@ enum block_enum
f9426a
 
f9426a
 #include "utils.h"
f9426a
 
f9426a
+extern void ulongest_fits_host_or_error (ULONGEST num);
f9426a
+
f9426a
 #endif /* #ifndef DEFS_H */