Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew STUBBS <andrew.stubbs@st.com>
To: GDB Patches <gdb-patches@sourceware.org>
Subject: [PATCH] Fix segfault on empty else
Date: Tue, 20 Jun 2006 14:34:00 -0000	[thread overview]
Message-ID: <44980741.4040404@st.com> (raw)

[-- 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;

             reply	other threads:[~2006-06-20 14:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-20 14:34 Andrew STUBBS [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44980741.4040404@st.com \
    --to=andrew.stubbs@st.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox