aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2010-06-01 12:47:33 +0000
committerPedro Alves <palves@redhat.com>2010-06-01 12:47:33 +0000
commitd149dd1dab5b2493780bf3abdcf3f80318271415 (patch)
tree440a2e06e5d82e57ed34f5fd61a8b5fafef0096b
parent46d00b8af141a8ef29f4b9cd49ab70839b6e5ba8 (diff)
downloadgdb-d149dd1dab5b2493780bf3abdcf3f80318271415.zip
gdb-d149dd1dab5b2493780bf3abdcf3f80318271415.tar.gz
gdb-d149dd1dab5b2493780bf3abdcf3f80318271415.tar.bz2
* server.c (handle_query) <qSupported>: Do two passes over the
qSupported string to avoid nesting strtok.
-rw-r--r--gdb/gdbserver/ChangeLog5
-rw-r--r--gdb/gdbserver/server.c48
2 files changed, 39 insertions, 14 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index b7d0c0c..6d77af6 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-01 Pedro Alves <pedro@codesourcery.com>
+
+ * server.c (handle_query) <qSupported>: Do two passes over the
+ qSupported string to avoid nesting strtok.
+
2010-05-28 Jan Kratochvil <jan.kratochvil@redhat.com>
* Makefile.in (SFILES): Add $(srcdir)/proc-service.list.
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 75b9d88..25845a7 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -1346,20 +1346,40 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
feature will follow a ':', and latter features will follow
';'. */
if (*p == ':')
- for (p = strtok (p + 1, ";");
- p != NULL;
- p = strtok (NULL, ";"))
- {
- if (strcmp (p, "multiprocess+") == 0)
- {
- /* GDB supports and wants multi-process support if
- possible. */
- if (target_supports_multi_process ())
- multi_process = 1;
- }
- else
- target_process_qsupported (p);
- }
+ {
+ char **qsupported = NULL;
+ int count = 0;
+ int i;
+
+ /* Two passes, to avoid nested strtok calls in
+ target_process_qsupported. */
+ for (p = strtok (p + 1, ";");
+ p != NULL;
+ p = strtok (NULL, ";"))
+ {
+ count++;
+ qsupported = xrealloc (qsupported, count * sizeof (char *));
+ qsupported[count - 1] = xstrdup (p);
+ }
+
+ for (i = 0; i < count; i++)
+ {
+ p = qsupported[i];
+ if (strcmp (p, "multiprocess+") == 0)
+ {
+ /* GDB supports and wants multi-process support if
+ possible. */
+ if (target_supports_multi_process ())
+ multi_process = 1;
+ }
+ else
+ target_process_qsupported (p);
+
+ free (p);
+ }
+
+ free (qsupported);
+ }
sprintf (own_buf, "PacketSize=%x;QPassSignals+", PBUFSIZ - 1);