This is the mail archive of the insight@sourceware.org mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/2] Add an assert that we're not overflowing the register cache.


I'm running on x86-64 linux, and I'm building with --enable-targets=all
(not sure if this makes a difference).  As I start up insight the
setup_architecture_data method is called, and this allocates a register
cache, however, at this point, without know what target binary will be
loaded the exact number of target registers is unknown.

Next I load up a target executable, and run to main.

Finally, I open up the register window.  At this point an attempt is
made to access the register cache for all available registers, however,
the number of registers has grown as a result of loading a target
executable, insight then proceeds to corrupt a random area of memory
off the end of the register cache.

This patch doesn't fix the issue, but adds an assert to detect the bug.

OK to apply?

Thanks,
Andrew

gdb/gdbtk/ChangeLog

2013-09-05  Andrew Burgess  <aburgess@broadcom.com>
 
	* generic/gdbk-register.c (old_regs_count): New variable.
	(register_changed_p): Add new assert.
	(setup_architecture_data): Initialise old_regs_count.
 
Index: ./gdb/gdbtk/generic/gdbtk-register.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-register.c,v
retrieving revision 1.48
diff -u -p -r1.48 gdbtk-register.c
--- ./gdb/gdbtk/generic/gdbtk-register.c	5 Sep 2013 13:14:28 -0000	1.48
+++ ./gdb/gdbtk/generic/gdbtk-register.c	5 Sep 2013 13:46:08 -0000
@@ -63,6 +63,7 @@ static void get_register_types (int regn
    It is an array of (NUM_REGS+NUM_PSEUDO_REGS)*MAX_REGISTER_RAW_SIZE bytes. */
 
 static char *old_regs = NULL;
+static int old_regs_count = 0;
 static int *regformat = (int *)NULL;
 static struct type **regtype = (struct type **)NULL;
 
@@ -443,6 +444,7 @@ static void
 register_changed_p (int regnum, map_arg arg)
 {
   gdb_byte raw_buffer[MAX_REGISTER_SIZE];
+  gdb_assert (regnum < old_regs_count);
 
   if (!target_has_registers
       || !deprecated_frame_register_read (get_selected_frame (NULL), regnum,
@@ -472,6 +474,7 @@ setup_architecture_data (void)
 
   numregs = (gdbarch_num_regs (get_current_arch ())
 	     + gdbarch_num_pseudo_regs (get_current_arch ()));
+  old_regs_count = numregs;
   old_regs = xcalloc (1, numregs * MAX_REGISTER_SIZE + 1);
   regformat = (int *)xcalloc (numregs, sizeof(int));
   regtype = (struct type **)xcalloc (numregs, sizeof(struct type **));




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]