public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/riscv: Fix oob memory access when printing info registers
@ 2023-08-31 11:24 Ciaran Woodward
  2023-08-31 21:58 ` Kevin Buettner
  2023-09-01 11:13 ` [PATCH v2] " Ciaran Woodward
  0 siblings, 2 replies; 3+ messages in thread
From: Ciaran Woodward @ 2023-08-31 11:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Ciaran Woodward

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).
---
 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..0bae952156e 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-01 11:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31 11:24 [PATCH] gdb/riscv: Fix oob memory access when printing info registers Ciaran Woodward
2023-08-31 21:58 ` Kevin Buettner
2023-09-01 11:13 ` [PATCH v2] " Ciaran Woodward

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).