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]

[PATCH] Fix segfault on empty else


The attached patch fixes a segmentation fault that occurs when a GDB script has an empty else clause.

E.g.

if $cond
  echo here\n
else
  # boom
end

The command structure is apparently read correctly (from the user's perspective), but GDB will crash when it tries to a) execute the else clause ($cond == 0), or b) free the command, if the command is not in a define or the user-defined command is redefined.

This problem is caused by a pointer that is only initialised when it is first used, which is never when there are no commands.

:ADDPATCH CLI:

Andrew Stubbs
2006-06-20  Andrew Stubbs  <andrew.stubbs@st.com>

        * cli/cli-script.c (realloc_body_list): Zero new parts of body_list.


Index: src/gdb/cli/cli-script.c
===================================================================
--- src.orig/gdb/cli/cli-script.c	2006-04-07 14:31:15.000000000 +0100
+++ src/gdb/cli/cli-script.c	2006-06-20 15:15:25.000000000 +0100
@@ -701,6 +701,7 @@ realloc_body_list (struct command_line *
     xmalloc (sizeof (struct command_line *) * new_length);
 
   memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
+  memset (body_list + n, 0, sizeof (struct command_line *) * (new_length - n));
 
   xfree (command->body_list);
   command->body_list = body_list;

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