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