Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix segfault on empty else
@ 2006-06-20 14:34 Andrew STUBBS
  2006-06-20 20:17 ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew STUBBS @ 2006-06-20 14:34 UTC (permalink / raw)
  To: GDB Patches

[-- Attachment #1: Type: text/plain, Size: 576 bytes --]

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

[-- Attachment #2: empty-else.patch --]
[-- Type: text/plain, Size: 716 bytes --]

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;

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-07-07 13:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-20 14:34 [PATCH] Fix segfault on empty else Andrew STUBBS
2006-06-20 20:17 ` Daniel Jacobowitz
2006-06-21 10:50   ` Andrew STUBBS
2006-07-06 13:30     ` Daniel Jacobowitz
2006-07-06 16:19       ` Andrew STUBBS
2006-07-06 16:23         ` Daniel Jacobowitz
2006-07-07 11:08           ` Andrew STUBBS
2006-07-07 12:39             ` Daniel Jacobowitz
2006-07-07 13:36               ` Andrew STUBBS

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox