Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Ciaran Woodward <ciaranwoodward@xmos.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2] gdb/riscv: Fix oob memory access when printing info registers
Date: Fri,  1 Sep 2023 12:13:55 +0100	[thread overview]
Message-ID: <20230901111355.18785-1-ciaranwoodward@xmos.com> (raw)
In-Reply-To: <20230831112449.3822-1-ciaranwoodward@xmos.com>

If the length of a register name was greater than 15,
print_spaces was called with a negative number, which
prints random data from the heap instead of the requested
number of spaces.

This could happen if a target-description file was used
to specify additional long-named registers.

Fix is simple - don't ask for fewer than 1 space (since
we still want column separation).
---

I don't have push privileges, so please can you push this for me!

 gdb/riscv-tdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index ae18eb64452..3a2891c2c92 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1145,7 +1145,7 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
   enum tab_stops { value_column_1 = 15 };
 
   gdb_puts (name, file);
-  print_spaces (value_column_1 - strlen (name), file);
+  print_spaces (std::max<int> (1, value_column_1 - strlen (name)), file);
 
   try
     {
-- 
2.25.1


      parent reply	other threads:[~2023-09-01 11:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31 11:24 [PATCH] " Ciaran Woodward
2023-08-31 21:58 ` Kevin Buettner via Gdb-patches
2023-09-01 11:13 ` Ciaran Woodward [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230901111355.18785-1-ciaranwoodward@xmos.com \
    --to=ciaranwoodward@xmos.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox