From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29697 invoked by alias); 4 Apr 2006 19:58:01 -0000 Received: (qmail 29686 invoked by uid 22791); 4 Apr 2006 19:58:01 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 04 Apr 2006 19:58:00 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k34JvwmT022950; Tue, 4 Apr 2006 15:57:58 -0400 Received: from potter.sfbay.redhat.com (potter.sfbay.redhat.com [172.16.27.15]) by int-mx1.corp.redhat.com (8.12.11.20060308/8.11.6) with ESMTP id k34Jvv7k010888; Tue, 4 Apr 2006 15:57:58 -0400 Received: from [172.16.24.50] (bluegiant.sfbay.redhat.com [172.16.24.50]) by potter.sfbay.redhat.com (8.12.8/8.12.8) with ESMTP id k34JvtTq013086; Tue, 4 Apr 2006 15:57:56 -0400 Message-ID: <4432CFC1.4090308@redhat.com> Date: Tue, 04 Apr 2006 19:58:00 -0000 From: Michael Snyder User-Agent: Mozilla Thunderbird 1.0.7-1.4.1 (X11/20050929) MIME-Version: 1.0 To: Andrew STUBBS CC: GDB Patches Subject: Re: [PATCH] allow nested sourced commands References: <442BD6F1.8070804@st.com> <44324959.4@st.com> <44324B1E.3070409@st.com> In-Reply-To: <44324B1E.3070409@st.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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-04/txt/msg00034.txt.bz2 Andrew STUBBS wrote: >> >>> I have discovered a problem in the GDB command line reading code. >>> >>> command_line_input() uses a static buffer to hold the current >>> command. This means that it is not properly re-entrant - commands >>> that contain other commands, such as user defined commands, are not >>> handled safely. >> >> >> See http://sources.redhat.com/ml/gdb-patches/2006-03/msg00356.html >> >> The attached patch should fix the problem. >> >> I tried to fix the problem in command_line_input, but there were too >> many ways for the string to leak, so I have opted for the simpler fix, >> even though it feels like treating the symptoms, not the problem. >> >> Anyway, with this patch it no longer attempts to read data that has >> been overwritten, so everything works fine. Valgrind reports no >> problems with >> the test case I posted before. >> >> Andrew Stubbs Well, it has the virtue of simplicity! At first glance, it seems conceptually valid. I think you need a clean-up, though. What if it errors? > ------------------------------------------------------------------------ > > 2006-04-04 Andrew Stubbs > > * cli/cli-script.c (struct user_args): Add command field. > (arg_cleanup): Free command string. > (setup_user_args): Copy the command line before relying on it. > > Index: src/gdb/cli/cli-script.c > =================================================================== > --- src.orig/gdb/cli/cli-script.c 2006-04-04 10:53:26.000000000 +0100 > +++ src/gdb/cli/cli-script.c 2006-04-04 11:09:33.000000000 +0100 > @@ -54,6 +54,7 @@ static int control_level; > struct user_args > { > struct user_args *next; > + char *command; > struct > { > char *arg; > @@ -483,6 +484,7 @@ arg_cleanup (void *ignore) > _("arg_cleanup called with no user args.\n")); > > user_args = user_args->next; > + xfree (oargs->command); > xfree (oargs); > } > > @@ -507,6 +509,8 @@ setup_user_args (char *p) > if (p == NULL) > return old_chain; > > + user_args->command = p = xstrdup (p); > + > while (*p) > { > char *start_arg;