aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-05-05 14:54:33 -0400
committerMike Frysinger <vapier@gentoo.org>2021-05-05 23:33:16 -0400
commit75070a4ede3760d4185c994200b40c9a35687eb4 (patch)
treec39fa3c90b5477908c863a51e7f3b5591e7420bb
parent4467df35a93e4c8e5ff7549e8d23324c64f527bd (diff)
downloadgdb-75070a4ede3760d4185c994200b40c9a35687eb4.zip
gdb-75070a4ede3760d4185c994200b40c9a35687eb4.tar.gz
gdb-75070a4ede3760d4185c994200b40c9a35687eb4.tar.bz2
sim: m32c/rl78/rx: fix command parsing
Use buildargv to avoid writing to const memory and freeing invalid pointers, and to avoid doing any string parsing ourselves.
-rw-r--r--sim/m32c/ChangeLog5
-rw-r--r--sim/m32c/gdb-if.c39
-rw-r--r--sim/rl78/ChangeLog5
-rw-r--r--sim/rl78/gdb-if.c44
-rw-r--r--sim/rx/ChangeLog5
-rw-r--r--sim/rx/gdb-if.c41
6 files changed, 59 insertions, 80 deletions
diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog
index a7351d6..b60faf5 100644
--- a/sim/m32c/ChangeLog
+++ b/sim/m32c/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-05 Mike Frysinger <vapier@gentoo.org>
+
+ * gdb-if.c: Include libiberty.h.
+ (sim_do_command): Rewrite to use buildargv.
+
2021-05-04 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.
diff --git a/sim/m32c/gdb-if.c b/sim/m32c/gdb-if.c
index 92e447f..c2aff06 100644
--- a/sim/m32c/gdb-if.c
+++ b/sim/m32c/gdb-if.c
@@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <ctype.h>
#include "ansidecl.h"
+#include "libiberty.h"
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
#include "gdb/signals.h"
@@ -648,37 +649,25 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p)
void
sim_do_command (SIM_DESC sd, const char *cmd)
{
- const char *args;
- char *p = strdup (cmd);
+ const char *arg;
+ char **argv = buildargv (cmd);
check_desc (sd);
- /* Skip leading whitespace. */
- while (isspace (*p))
- p++;
-
- /* Find the extent of the command word. */
- for (p = cmd; *p; p++)
- if (isspace (*p))
- break;
-
- /* Null-terminate the command word, and record the start of any
- further arguments. */
- if (*p)
+ cmd = arg = "";
+ if (argv != NULL)
{
- *p = '\0';
- args = p + 1;
- while (isspace (*args))
- args++;
+ if (argv[0] != NULL)
+ cmd = argv[0];
+ if (argv[1] != NULL)
+ arg = argv[1];
}
- else
- args = p;
if (strcmp (cmd, "trace") == 0)
{
- if (strcmp (args, "on") == 0)
+ if (strcmp (arg, "on") == 0)
trace = 1;
- else if (strcmp (args, "off") == 0)
+ else if (strcmp (arg, "off") == 0)
trace = 0;
else
printf ("The 'sim trace' command expects 'on' or 'off' "
@@ -686,9 +675,9 @@ sim_do_command (SIM_DESC sd, const char *cmd)
}
else if (strcmp (cmd, "verbose") == 0)
{
- if (strcmp (args, "on") == 0)
+ if (strcmp (arg, "on") == 0)
verbose = 1;
- else if (strcmp (args, "off") == 0)
+ else if (strcmp (arg, "off") == 0)
verbose = 0;
else
printf ("The 'sim verbose' command expects 'on' or 'off'"
@@ -698,7 +687,7 @@ sim_do_command (SIM_DESC sd, const char *cmd)
printf ("The 'sim' command expects either 'trace' or 'verbose'"
" as a subcommand.\n");
- free (p);
+ freeargv (argv);
}
char **
diff --git a/sim/rl78/ChangeLog b/sim/rl78/ChangeLog
index baaf6d8..f26d4d7 100644
--- a/sim/rl78/ChangeLog
+++ b/sim/rl78/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-05 Mike Frysinger <vapier@gentoo.org>
+
+ * gdb-if.c: Include libiberty.h.
+ (sim_do_command): Rewrite to use buildargv.
+
2021-05-04 Mike Frysinger <vapier@gentoo.org>
* cpu.c (trace_register_init): Add missing (void).
diff --git a/sim/rl78/gdb-if.c b/sim/rl78/gdb-if.c
index 7119214..f4b6754 100644
--- a/sim/rl78/gdb-if.c
+++ b/sim/rl78/gdb-if.c
@@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#include "ansidecl.h"
+#include "libiberty.h"
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
#include "gdb/signals.h"
@@ -533,40 +534,25 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p)
void
sim_do_command (SIM_DESC sd, const char *cmd)
{
- const char *args;
- char *p = strdup (cmd);
+ const char *arg;
+ char **argv = buildargv (cmd);
check_desc (sd);
- if (cmd == NULL)
+ cmd = arg = "";
+ if (argv != NULL)
{
- cmd = "";
- args = "";
- }
- else
- {
- /* Skip leading whitespace. */
- while (isspace (*p))
- p++;
-
- /* Null-terminate the command word, and record the start of any
- further arguments. */
- if (*p)
- {
- *p = '\0';
- args = p + 1;
- while (isspace (*args))
- args++;
- }
- else
- args = p;
+ if (argv[0] != NULL)
+ cmd = argv[0];
+ if (argv[1] != NULL)
+ arg = argv[1];
}
if (strcmp (cmd, "trace") == 0)
{
- if (strcmp (args, "on") == 0)
+ if (strcmp (arg, "on") == 0)
trace = 1;
- else if (strcmp (args, "off") == 0)
+ else if (strcmp (arg, "off") == 0)
trace = 0;
else
printf ("The 'sim trace' command expects 'on' or 'off' "
@@ -574,11 +560,11 @@ sim_do_command (SIM_DESC sd, const char *cmd)
}
else if (strcmp (cmd, "verbose") == 0)
{
- if (strcmp (args, "on") == 0)
+ if (strcmp (arg, "on") == 0)
verbose = 1;
- else if (strcmp (args, "noisy") == 0)
+ else if (strcmp (arg, "noisy") == 0)
verbose = 2;
- else if (strcmp (args, "off") == 0)
+ else if (strcmp (arg, "off") == 0)
verbose = 0;
else
printf ("The 'sim verbose' command expects 'on', 'noisy', or 'off'"
@@ -588,7 +574,7 @@ sim_do_command (SIM_DESC sd, const char *cmd)
printf ("The 'sim' command expects either 'trace' or 'verbose'"
" as a subcommand.\n");
- free (p);
+ freeargv (argv);
}
/* Stub for command completion. */
diff --git a/sim/rx/ChangeLog b/sim/rx/ChangeLog
index 9a707e4..b941caf 100644
--- a/sim/rx/ChangeLog
+++ b/sim/rx/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-05 Mike Frysinger <vapier@gentoo.org>
+
+ * gdb-if.c: Include libiberty.h.
+ (sim_do_command): Rewrite to use buildargv.
+
2021-05-04 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.
diff --git a/sim/rx/gdb-if.c b/sim/rx/gdb-if.c
index 3d052e6..ec41910 100644
--- a/sim/rx/gdb-if.c
+++ b/sim/rx/gdb-if.c
@@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#include "ansidecl.h"
+#include "libiberty.h"
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
#include "gdb/signals.h"
@@ -794,37 +795,25 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p)
void
sim_do_command (SIM_DESC sd, const char *cmd)
{
- const char *args;
- char *p = strdup (cmd);
+ const char *arg;
+ char **argv = buildargv (cmd);
check_desc (sd);
- /* Skip leading whitespace. */
- while (isspace (*p))
- p++;
-
- /* Find the extent of the command word. */
- for (; *p != '\0'; p++)
- if (isspace (*p))
- break;
-
- /* Null-terminate the command word, and record the start of any
- further arguments. */
- if (*p != '\0')
+ cmd = arg = "";
+ if (argv != NULL)
{
- *p = '\0';
- args = p + 1;
- while (isspace (*args))
- args++;
+ if (argv[0] != NULL)
+ cmd = argv[0];
+ if (argv[1] != NULL)
+ arg = argv[1];
}
- else
- args = p;
if (strcmp (cmd, "trace") == 0)
{
- if (strcmp (args, "on") == 0)
+ if (strcmp (arg, "on") == 0)
trace = 1;
- else if (strcmp (args, "off") == 0)
+ else if (strcmp (arg, "off") == 0)
trace = 0;
else
printf ("The 'sim trace' command expects 'on' or 'off' "
@@ -832,11 +821,11 @@ sim_do_command (SIM_DESC sd, const char *cmd)
}
else if (strcmp (cmd, "verbose") == 0)
{
- if (strcmp (args, "on") == 0)
+ if (strcmp (arg, "on") == 0)
verbose = 1;
- else if (strcmp (args, "noisy") == 0)
+ else if (strcmp (arg, "noisy") == 0)
verbose = 2;
- else if (strcmp (args, "off") == 0)
+ else if (strcmp (arg, "off") == 0)
verbose = 0;
else
printf ("The 'sim verbose' command expects 'on', 'noisy', or 'off'"
@@ -846,7 +835,7 @@ sim_do_command (SIM_DESC sd, const char *cmd)
printf ("The 'sim' command expects either 'trace' or 'verbose'"
" as a subcommand.\n");
- free (p);
+ freeargv (argv);
}
char **