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