This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Resubmit reverse debugging [5/5]


Thiago Jung Bauermann wrote:
El mar, 07-10-2008 a las 19:20 -0700, Michael Snyder escribiÃ:
+static void
+exec_reverse_once (char *cmd, char *args, int from_tty)
+{
+  /* String buffer for command consing.  */
+  char reverse_command[512];
<snip>
+  sprintf (reverse_command, "%s %s", cmd, args ? args : "");
+
+  execution_direction = EXEC_REVERSE;
+  execute_command (reverse_command, from_tty);
+  do_cleanups (old_chain);

That fixed-length buffer being written with sprintf doesn't look good... What do you think about using xstrprintf instead? That will remove the possibility of buffer overflow, and also remove an arbitrary limit.

How about this? (the function pointer idea I leave for a future enhancement):


Index: reverse.c
===================================================================
RCS file: /cvs/src/src/gdb/Attic/reverse.c,v
retrieving revision 1.1.10.6
diff -u -p -r1.1.10.6 reverse.c
--- reverse.c	8 Oct 2008 00:26:28 -0000	1.1.10.6
+++ reverse.c	8 Oct 2008 21:03:59 -0000
@@ -44,8 +44,7 @@ static void exec_direction_default (void
 static void
 exec_reverse_once (char *cmd, char *args, int from_tty)
 {
-  /* String buffer for command consing.  */
-  char reverse_command[512];
+  char *reverse_command;
   enum exec_direction_kind dir = execution_direction;
   struct cleanup *old_chain;
 
@@ -59,9 +58,9 @@ exec_reverse_once (char *cmd, char *args
   if (!target_can_execute_reverse)
     error (_("Target %s does not support this command."), target_shortname);
 
+  reverse_command = xstrprintf ("%s %s", cmd, args ? args : "");
   old_chain = make_cleanup (exec_direction_default, NULL);
-  sprintf (reverse_command, "%s %s", cmd, args ? args : "");
-
+  make_cleanup (xfree, reverse_command);
   execution_direction = EXEC_REVERSE;
   execute_command (reverse_command, from_tty);
   do_cleanups (old_chain);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]