From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18058 invoked by alias); 20 Jun 2006 14:34:03 -0000 Received: (qmail 18047 invoked by uid 22791); 20 Jun 2006 14:34:03 -0000 X-Spam-Check-By: sourceware.org Received: from fra-del-03.spheriq.net (HELO fra-del-03.spheriq.net) (195.46.51.99) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 20 Jun 2006 14:33:59 +0000 Received: from fra-out-01.spheriq.net (fra-out-01.spheriq.net [195.46.51.129]) by fra-del-03.spheriq.net with ESMTP id k5KEXrLW030417 for ; Tue, 20 Jun 2006 14:33:53 GMT Received: from fra-cus-01.spheriq.net (fra-cus-01.spheriq.net [195.46.51.37]) by fra-out-01.spheriq.net with ESMTP id k5KEXgVd004986 for ; Tue, 20 Jun 2006 14:33:44 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-01.spheriq.net with ESMTP id k5KEXft5014199 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Tue, 20 Jun 2006 14:33:42 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3547BDA43 for ; Tue, 20 Jun 2006 14:33:41 +0000 (GMT) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2107D4759D for ; Tue, 20 Jun 2006 14:33:39 +0000 (GMT) Received: from [164.129.15.13] (bri1043.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.5.8-GR) with ESMTP id CHT05012 (AUTH stubbsa); Tue, 20 Jun 2006 15:33:37 +0100 (BST) Message-ID: <44980741.4040404@st.com> Date: Tue, 20 Jun 2006 14:34:00 -0000 From: Andrew STUBBS User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: GDB Patches Subject: [PATCH] Fix segfault on empty else Content-Type: multipart/mixed; boundary="------------040100010705060602060505" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-06/txt/msg00280.txt.bz2 This is a multi-part message in MIME format. --------------040100010705060602060505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 576 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 --------------040100010705060602060505 Content-Type: text/plain; name="empty-else.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="empty-else.patch" Content-length: 716 2006-06-20 Andrew Stubbs * 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; --------------040100010705060602060505--