From 81aa19c303c94f549cb9ae343cfe4b635b4e888c Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 14 Feb 2023 07:03:11 -0700 Subject: Do not cast away const in agent_run_command While investigating something else, I noticed some weird code in agent_run_command (use of memcpy rather than strcpy). Then I noticed that 'cmd' is used as both an in and out parameter, despite being const. Casting away const like this is bad. This patch removes the const and fixes the memcpy. I also added a static assert to assure myself that the code in gdbserver is correct -- gdbserver is passing its own buffer directly to agent_run_command. Reviewed-By: Andrew Burgess --- gdbserver/server.cc | 5 +++++ gdbserver/tracepoint.cc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'gdbserver') diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 21fb51a45d1..46dfe70838b 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -51,6 +51,11 @@ #include "gdbsupport/scoped_restore.h" #include "gdbsupport/search.h" +/* PBUFSIZ must also be at least as big as IPA_CMD_BUF_SIZE, because + the client state data is passed directly to some agent + functions. */ +gdb_static_assert (PBUFSIZ >= IPA_CMD_BUF_SIZE); + #define require_running_or_return(BUF) \ if (!target_running ()) \ { \ diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc index 37a9a8c5b7c..b59077a3896 100644 --- a/gdbserver/tracepoint.cc +++ b/gdbserver/tracepoint.cc @@ -6820,7 +6820,7 @@ run_inferior_command (char *cmd, int len) target_pause_all (false); uninsert_all_breakpoints (); - err = agent_run_command (pid, (const char *) cmd, len); + err = agent_run_command (pid, cmd, len); reinsert_all_breakpoints (); target_unpause_all (false); -- cgit v1.2.1