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

e1d87d
http://sourceware.org/ml/gdb-patches/2012-09/msg00632.html
e1d87d
Subject: [PATCH 2/4] Add a check to ensure that a type may fit into host memory
e1d87d
e1d87d
e1d87d
--MP_/PnL6l3LUsXWpZ/olqawWlzb
e1d87d
Content-Type: text/plain; charset=US-ASCII
e1d87d
Content-Transfer-Encoding: 7bit
e1d87d
Content-Disposition: inline
e1d87d
e1d87d
Hi,
e1d87d
e1d87d
This is part two of the bitpos expansion patch.  This implements checks
e1d87d
in some places in the code to ensure that a type size in ULONGEST is
e1d87d
small enough to fit into host memory.  Tested for regressions on x86_64
e1d87d
Fedora 16.
e1d87d
e1d87d
Regards,
e1d87d
Siddhesh
e1d87d
e1d87d
--MP_/PnL6l3LUsXWpZ/olqawWlzb
e1d87d
Content-Type: text/plain
e1d87d
Content-Transfer-Encoding: quoted-printable
e1d87d
Content-Disposition: attachment; filename=ChangeLog-ensure_sizet
e1d87d
e1d87d
gdb/ChangeLog
e1d87d
e1d87d
	* alpha-tdep.c (alpha_push_dummy_call) Check for underflow in
e1d87d
	SP.
e1d87d
	* cp-valprint (cp_print_value): Ensure BASECLASS fits into
e1d87d
	size_t.
e1d87d
	* dwarf2loc.c (read_pieced_value): Ensure that THIS_SIZE fits
e1d87d
	into size_t.
e1d87d
	(write_pieced_value): Likewise.
e1d87d
	* findcmd.c (parse_find_args): Ensure PATTERN_BUF_SIZE fits into
e1d87d
	size_t.
e1d87d
	* p-valprint (pascal_object_print_value): Ensure BASECLASS fits
e1d87d
	into size_t.
e1d87d
	* utils.c (ulongest_fits_host_or_error): New function to find if
e1d87d
	a ULONGEST number fits into size_t.
e1d87d
	* utils.h: Declare ulongest_fits_host_or_error.
e1d87d
	* valops.c (search_struct_method): Ensure BASECLASS fits into
e1d87d
	size_t.
e1d87d
	* value.c (allocate_value_lazy): Ensure TYPE fits into size_t.
e1d87d
	(allocate_value_contents): Likewise.
e1d87d
	(set_value_enclosing_type): Ensure NEW_ENCL_TYPE fits into
e1d87d
	size_t.
e1d87d
	* vax-tdep.c (vax_return_value): Ensure that TYPE fits into
e1d87d
	size_t.
e1d87d
e1d87d
--MP_/PnL6l3LUsXWpZ/olqawWlzb
e1d87d
Content-Type: text/x-patch
e1d87d
Content-Transfer-Encoding: 7bit
e1d87d
Content-Disposition: attachment; filename=bitpos-ensure-size_t.patch
e1d87d
e1d87d
Index: gdb-8.0/gdb/alpha-tdep.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/alpha-tdep.c	2017-08-19 20:07:45.469330496 +0200
e1d87d
+++ gdb-8.0/gdb/alpha-tdep.c	2017-08-19 20:07:50.670379152 +0200
e1d87d
@@ -414,6 +414,13 @@
e1d87d
     accumulate_size = 0;
e1d87d
   else
e1d87d
     accumulate_size -= sizeof(arg_reg_buffer);
e1d87d
+
e1d87d
+  /* Check for underflow.  */
e1d87d
+  if (sp - accumulate_size > sp)
e1d87d
+    error (_("Insufficient memory in GDB host for arguments, "
e1d87d
+	     "need %s bytes, but less than %s bytes available."),
e1d87d
+	   plongest (accumulate_size), plongest (CORE_ADDR_MAX - sp));
e1d87d
+
e1d87d
   sp -= accumulate_size;
e1d87d
 
e1d87d
   /* Keep sp aligned to a multiple of 16 as the ABI requires.  */
e1d87d
Index: gdb-8.0/gdb/cp-valprint.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/cp-valprint.c	2017-08-19 20:07:45.470330505 +0200
e1d87d
+++ gdb-8.0/gdb/cp-valprint.c	2017-08-19 20:07:50.670379152 +0200
e1d87d
@@ -537,6 +537,8 @@
e1d87d
 		  gdb_byte *buf;
e1d87d
 		  struct cleanup *back_to;
e1d87d
 
e1d87d
+		  ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
e1d87d
+
e1d87d
 		  buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
e1d87d
 		  back_to = make_cleanup (xfree, buf);
e1d87d
 
e1d87d
Index: gdb-8.0/gdb/findcmd.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/findcmd.c	2017-08-19 20:07:45.472330524 +0200
e1d87d
+++ gdb-8.0/gdb/findcmd.c	2017-08-19 20:07:50.672379171 +0200
e1d87d
@@ -186,6 +186,7 @@
e1d87d
 	  size_t current_offset = pattern_buf_end - pattern_buf;
e1d87d
 
e1d87d
 	  pattern_buf_size = pattern_buf_size_need * 2;
e1d87d
+	  ulongest_fits_host_or_error (pattern_buf_size);
e1d87d
 	  pattern_buf = (gdb_byte *) xrealloc (pattern_buf, pattern_buf_size);
e1d87d
 	  pattern_buf_end = pattern_buf + current_offset;
e1d87d
 	}
e1d87d
Index: gdb-8.0/gdb/p-valprint.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/p-valprint.c	2017-08-19 20:07:45.472330524 +0200
e1d87d
+++ gdb-8.0/gdb/p-valprint.c	2017-08-19 20:07:50.673379180 +0200
e1d87d
@@ -772,6 +772,7 @@
e1d87d
 	      gdb_byte *buf;
e1d87d
 	      struct cleanup *back_to;
e1d87d
 
e1d87d
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
e1d87d
 	      buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
e1d87d
 	      back_to = make_cleanup (xfree, buf);
e1d87d
 
e1d87d
Index: gdb-8.0/gdb/utils.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/utils.c	2017-08-19 20:07:45.473330533 +0200
e1d87d
+++ gdb-8.0/gdb/utils.c	2017-08-19 20:07:50.673379180 +0200
e1d87d
@@ -2776,6 +2776,18 @@
e1d87d
   return addr;
e1d87d
 }
e1d87d
 
e1d87d
+/* Ensure that the input NUM is not larger than the maximum capacity of the
e1d87d
+   host system.  We choose SIZE_MAX / 8 as a conservative estimate of the size
e1d87d
+   of a resource that a system may allocate.  */
e1d87d
+void
e1d87d
+ulongest_fits_host_or_error (ULONGEST num)
e1d87d
+{
e1d87d
+  if (num > SIZE_MAX / 8)
e1d87d
+    error (_("Insufficient memory in host GDB for object of size %s bytes, "
e1d87d
+	     "maximum allowed %s bytes."), pulongest (num),
e1d87d
+	   pulongest (SIZE_MAX / 8));
e1d87d
+}
e1d87d
+
e1d87d
 char *
e1d87d
 gdb_realpath (const char *filename)
e1d87d
 {
e1d87d
Index: gdb-8.0/gdb/valops.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/valops.c	2017-08-19 20:07:45.474330542 +0200
e1d87d
+++ gdb-8.0/gdb/valops.c	2017-08-19 20:07:50.674379190 +0200
e1d87d
@@ -2100,6 +2100,7 @@
e1d87d
 	      struct cleanup *back_to;
e1d87d
 	      CORE_ADDR address;
e1d87d
 
e1d87d
+	      ulongest_fits_host_or_error (TYPE_LENGTH (baseclass));
e1d87d
 	      tmp = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
e1d87d
 	      back_to = make_cleanup (xfree, tmp);
e1d87d
 	      address = value_address (*arg1p);
e1d87d
Index: gdb-8.0/gdb/value.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/value.c	2017-08-19 20:07:45.476330561 +0200
e1d87d
+++ gdb-8.0/gdb/value.c	2017-08-19 20:07:50.675379199 +0200
e1d87d
@@ -936,6 +936,7 @@
e1d87d
      description correctly.  */
e1d87d
   check_typedef (type);
e1d87d
 
e1d87d
+  ulongest_fits_host_or_error (TYPE_LENGTH (type));
e1d87d
   val = XCNEW (struct value);
e1d87d
   val->contents = NULL;
e1d87d
   val->next = all_values;
e1d87d
@@ -1033,6 +1034,8 @@
e1d87d
 static void
e1d87d
 allocate_value_contents (struct value *val)
e1d87d
 {
e1d87d
+  ulongest_fits_host_or_error (TYPE_LENGTH (val->enclosing_type));
e1d87d
+
e1d87d
   if (!val->contents)
e1d87d
     {
e1d87d
       check_type_length_before_alloc (val->enclosing_type);
e1d87d
@@ -3093,6 +3096,7 @@
e1d87d
   if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val)))
e1d87d
     {
e1d87d
       check_type_length_before_alloc (new_encl_type);
e1d87d
+      ulongest_fits_host_or_error (TYPE_LENGTH (new_encl_type));
e1d87d
       val->contents
e1d87d
 	= (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
e1d87d
     }
e1d87d
Index: gdb-8.0/gdb/vax-tdep.c
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/vax-tdep.c	2017-08-19 20:07:45.476330561 +0200
e1d87d
+++ gdb-8.0/gdb/vax-tdep.c	2017-08-19 20:07:50.675379199 +0200
e1d87d
@@ -219,6 +219,7 @@
e1d87d
 	  ULONGEST addr;
e1d87d
 
e1d87d
 	  regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
e1d87d
+	  ulongest_fits_host_or_error (TYPE_LENGTH (type));
e1d87d
 	  read_memory (addr, readbuf, len);
e1d87d
 	}
e1d87d
 
e1d87d
Index: gdb-8.0/gdb/defs.h
e1d87d
===================================================================
e1d87d
--- gdb-8.0.orig/gdb/defs.h	2017-08-19 20:07:45.476330561 +0200
e1d87d
+++ gdb-8.0/gdb/defs.h	2017-08-19 20:07:50.676379208 +0200
e1d87d
@@ -750,4 +750,6 @@
e1d87d
 
e1d87d
 #include "utils.h"
e1d87d
 
e1d87d
+extern void ulongest_fits_host_or_error (ULONGEST num);
e1d87d
+
e1d87d
 #endif /* #ifndef DEFS_H */