This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc] [8/9] Multi-target support: Fix do_setshow_command buffer overflow
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 26 Oct 2007 03:17:58 +0200 (CEST)
- Subject: [rfc] [8/9] Multi-target support: Fix do_setshow_command buffer overflow
Hello,
this was the last remaining problem I ran into with --enable-targets=all:
"set architecture" with no arguments crashed because the long list of
available options overran a fixed-size buffer in do_setshow_command :-)
Fixed by making the buffer dynamically sized.
Bye,
Ulrich
ChangeLog:
* cli/cli-setshow.c (do_setshow_command): Use dynamically sized buffer
to construct error message if no argument was supplied.
diff -urNp gdb-orig/gdb/cli/cli-setshow.c gdb-head/gdb/cli/cli-setshow.c
--- gdb-orig/gdb/cli/cli-setshow.c 2007-10-20 16:06:26.000000000 +0200
+++ gdb-head/gdb/cli/cli-setshow.c 2007-10-25 01:05:51.000000000 +0200
@@ -242,16 +242,22 @@ do_setshow_command (char *arg, int from_
/* if no argument was supplied, print an informative error message */
if (arg == NULL)
{
- char msg[1024];
- strcpy (msg, "Requires an argument. Valid arguments are ");
+ char *msg;
+ int msg_len = 0;
+ for (i = 0; c->enums[i]; i++)
+ msg_len += strlen (c->enums[i]) + 2;
+
+ msg = xmalloc (msg_len);
+ *msg = '\0';
+ make_cleanup (xfree, msg);
+
for (i = 0; c->enums[i]; i++)
{
if (i != 0)
strcat (msg, ", ");
strcat (msg, c->enums[i]);
}
- strcat (msg, ".");
- error (("%s"), msg);
+ error (_("Requires an argument. Valid arguments are %s."), msg);
}
p = strchr (arg, ' ');
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com