From 48d93c7500d9f0cee303e547f773ded6e325c6f6 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 16 May 2005 10:24:37 +0000 Subject: [PATCH] * linux-low.c (fetch_register): Ensure buffer size is a multiple of sizeof (PTRACE_XFER_TYPE). (usr_store_inferior_registers): Likewise. Zero out excess bytes. --- gdb/gdbserver/ChangeLog | 6 ++++++ gdb/gdbserver/linux-low.c | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 311d3ec6705..90aa0d22a8b 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,9 @@ +2005-05-16 Ulrich Weigand + + * linux-low.c (fetch_register): Ensure buffer size is a multiple + of sizeof (PTRACE_XFER_TYPE). + (usr_store_inferior_registers): Likewise. Zero out excess bytes. + 2005-05-12 Orjan Friberg * target.h (struct target_ops): Add insert_watchpoint, diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index c7dab4cae0c..3795cb6996e 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -1095,7 +1095,7 @@ static void fetch_register (int regno) { CORE_ADDR regaddr; - register int i; + int i, size; char *buf; if (regno >= the_low_target.num_regs) @@ -1106,8 +1106,10 @@ fetch_register (int regno) regaddr = register_addr (regno); if (regaddr == -1) return; - buf = alloca (register_size (regno)); - for (i = 0; i < register_size (regno); i += sizeof (PTRACE_XFER_TYPE)) + size = (register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1) + & - sizeof (PTRACE_XFER_TYPE); + buf = alloca (size); + for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE)) { errno = 0; *(PTRACE_XFER_TYPE *) (buf + i) = @@ -1147,7 +1149,7 @@ static void usr_store_inferior_registers (int regno) { CORE_ADDR regaddr; - int i; + int i, size; char *buf; if (regno >= 0) @@ -1162,9 +1164,12 @@ usr_store_inferior_registers (int regno) if (regaddr == -1) return; errno = 0; - buf = alloca (register_size (regno)); + size = (register_size (regno) + sizeof (PTRACE_XFER_TYPE) - 1) + & - sizeof (PTRACE_XFER_TYPE); + buf = alloca (size); + memset (buf, 0, size); collect_register (regno, buf); - for (i = 0; i < register_size (regno); i += sizeof (PTRACE_XFER_TYPE)) + for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE)) { errno = 0; ptrace (PTRACE_POKEUSER, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, -- 2.30.2