This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch/in] Stop regcache out-of-bounds on i386
- From: Andrew Cagney <ac131313 at ges dot redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Tue, 13 Aug 2002 19:09:04 -0400
- Subject: [patch/in] Stop regcache out-of-bounds on i386
Hello,
Per MarkK's post. This fixes an out-of-bounds problem that the i386 on
freebsd was tickling (the problem was in generic code). The regcache
now only tries to invalidate the registers in the cache. To try to stop
this happening again, it has also gained a few extra assertions.
GNU/Linux Red Hat 7.3 didn't show regressions.
committed,
Andrew
2002-08-13 Andrew Cagney <cagney@redhat.com>
* regcache.c (init_regcache_descr): Overallocate the
raw_register_valid_p array including space for NUM_PSEUDO_REGS.
(registers_changed): Replace NUM_REGS+NUM_PSEUDO_REGS with
nr_raw_registers.
(set_register_cached): Add range checking assertions. Use
current_regcache.
Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/regcache.c,v
retrieving revision 1.52
diff -u -r1.52 regcache.c
--- regcache.c 13 Aug 2002 14:32:28 -0000 1.52
+++ regcache.c 13 Aug 2002 23:04:23 -0000
@@ -161,7 +161,12 @@
/* Construct a strictly RAW register cache. Don't allow pseudo's
into the register cache. */
descr->nr_raw_registers = NUM_REGS;
- descr->sizeof_raw_register_valid_p = NUM_REGS;
+
+ /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
+ array. This pretects GDB from erant code that accesses elements
+ of the global register_valid_p[] array in the range [NUM_REGS
+ .. NUM_REGS + NUM_PSEUDO_REGS). */
+ descr->sizeof_raw_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS;
/* Lay out the register cache. The pseud-registers are included in
the layout even though their value isn't stored in the register
@@ -431,7 +436,9 @@
void
set_register_cached (int regnum, int state)
{
- register_valid[regnum] = state;
+ gdb_assert (regnum >= 0);
+ gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
+ current_regcache->raw_register_valid_p[regnum] = state;
}
/* REGISTER_CHANGED
@@ -485,7 +492,7 @@
gdb gives control to the user (ie watchpoints). */
alloca (0);
- for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
+ for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
set_register_cached (i, 0);
if (registers_changed_hook)