From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13833 invoked by alias); 4 Jan 2010 12:15:24 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27556 Received: (qmail 5944 invoked from network); 4 Jan 2010 12:15:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.2.5 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Mon, 4 Jan 2010 12:15:12 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Problems with source command in precmd() Message-ID: <20100104121512.184c9350@news01> In-Reply-To: <091219155732.ZM9104@torch.brasslantern.com> References: <20091219224933.GA2785040@becquerel.illdefined.org> <091219155732.ZM9104@torch.brasslantern.com> Organization: CSR X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 04 Jan 2010 12:15:12.0514 (UTC) FILETIME=[90C6B620:01CA8D37] X-Scanned-By: MailControl A-09-22-10 (www.mailcontrol.com) on 10.71.0.140 On Sat, 19 Dec 2009 15:57:32 -0800 Bart Schaefer wrote: > On Dec 19, 10:49pm, Daniel Friesel wrote: > } > } there appear to be some crashes when using the source command in the > } precmd function. > > I can reproduce this. It's sufficient to run zsh -f and enter > > precmd() { source /dev/null } > > at the prompt, then accept-line a second time. This took some hunting down. valgrind was silent until the point where the crash happened. There is a recently added execsave() / execrestore() in the file execution loop. This is a good thing to do, but it wasn't sanitising enough of the state that it was saving to ensure it could be restored cleanly. In particular there appears to be a ghastly hack whereby setting "stophist == 3" is being used in precmd functions to influence a future iteration (instead of doing its proper job of controlling the history mechanism for each iteration), and this was causing nameless horrors to happen to the data referred to by the saved exec information. This is hard to test for without a handler for interactive tests. I couldn't provoke the problem with zsh -ci. Index: Src/lex.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/lex.c,v retrieving revision 1.52 diff -u -r1.52 lex.c --- Src/lex.c 3 Mar 2009 17:26:07 -0000 1.52 +++ Src/lex.c 4 Jan 2010 12:00:45 -0000 @@ -248,8 +248,11 @@ ls->histactive = histactive; ls->histdone = histdone; ls->stophist = stophist; + stophist = 0; ls->hline = chline; + chline = NULL; ls->hptr = hptr; + hptr = NULL; ls->hlinesz = hlinesz; ls->cstack = cmdstack; ls->csp = cmdsp; @@ -259,7 +262,9 @@ ls->tokstr = tokstr; ls->zshlextext = zshlextext; ls->bptr = bptr; + tokstr = zshlextext = bptr = NULL; ls->bsiz = bsiz; + bsiz = 256; ls->len = len; ls->chwords = chwords; ls->chwordlen = chwordlen; -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom