From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5867 invoked by alias); 21 Dec 2012 10:34:40 -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: 30930 Received: (qmail 11263 invoked from network); 21 Dec 2012 10:34:27 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f4-b7f6d6d000001620-c8-50d43b2e33d3 Date: Fri, 21 Dec 2012 10:34:21 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Segfault in =( ) substitution Message-id: <20121221103421.3192ec95@pwslap01u.europe.root.pri> In-reply-to: <20121221075751.GF2464@localhost.localdomain> References: <20121017202030.46014a7a@pws-pc.ntlworld.com> <20121017211603.6189d6f4@pws-pc.ntlworld.com> <20121221075751.GF2464@localhost.localdomain> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphluLIzCtJLcpLzFFi42I5/e/4ZV096ysBBu3L9SwONj9kcmD0WHXw A1MAYxSXTUpqTmZZapG+XQJXxqI7n5gLfklX3Ji9l7GB8a1oFyMnh4SAicTH4ytZIWwxiQv3 1rOB2EICSxkl9vdYQdjLmSQmztYFsVkEVCW2HL0JVs8mYCgxddNsRhBbREBc4uza8ywgtrCA lsTnexBxXgF7iX9NV8HqOQWsJC69X8XexcgFNPMRo8S2J6/ZQRL8AvoSV/9+YoI4wl5i5pUz UM2CEj8m3wMbygw0dPO2JlYIW15i85q3zBMYBWYhKZuFpGwWkrIFjMyrGEVTS5MLipPScw31 ihNzi0vz0vWS83M3MUJC8MsOxsXHrA4xCnAwKvHwMphdDhBiTSwrrsw9xCjBwawkwnvF7EqA EG9KYmVValF+fFFpTmrxIUYmDk6pBkbdlmKDDI/JshGhaYqu3BdnspizyCU13zJ+Nu9+pOaV r1pHNjqd31cXn/v129Xu/YZz30/y1K1rYP31z9O2gfl4/pH6x6tT3vay/07LO+Ca9aTl5Ksy 5sIzCRG/I8/svzVDcdX+xAvxT86/uHG581nQ0qxuCY7k7tKKbREa3mnt3hUN4YnSqUosxRmJ hlrMRcWJAIeWnrIfAgAA On Fri, 21 Dec 2012 15:57:51 +0800 Han Pingtian wrote: > I just noticed that this example crashed on zsh both 5.0 and 5.0.1. > If I compile zsh with debug enabled, it runs like this: > > % () { > function> print File $1: > function> cat $1 > function> } =(print hello) > File : > cat: : No such file or directory Glad you noticed this, it's a standard piece of luck we found out a day late... Anonymous functions can't be "simple", they need a valid process environment because (unlike normal function definitions) they can take arbitrary arguments, as in this case. (We could probe the arguments individually to see, but this fix is a good deal simpler.) If anyone can further elucidate the relationship between job control (in particular, the current job recorded in "thisjob") and shell code optimised to "simple" execution, feel free, otherwise whether or not it fails to crash because it's happened to pick up a version of "thisjob" from somewhere else isn't really interesting. The change in 30876 would have further perturbed the environment seen by execsimple(). Moral: when you spot "gr8 new featurez" you hadn't realised the shell could do, add tests for them. Index: Src/parse.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/parse.c,v retrieving revision 1.93 diff -p -u -r1.93 parse.c --- Src/parse.c 25 Oct 2012 08:54:33 -0000 1.93 +++ Src/parse.c 21 Dec 2012 10:20:59 -0000 @@ -846,7 +846,7 @@ par_cmd(int *complex) break; case FUNC: cmdpush(CS_FUNCDEF); - par_funcdef(); + par_funcdef(complex); cmdpop(); break; case DINBRACK: @@ -1420,7 +1420,7 @@ par_subsh(int *complex) /**/ static void -par_funcdef(void) +par_funcdef(int *complex) { int oecused = ecused, num = 0, onp, p, c = 0; int so, oecssub = ecssub; @@ -1471,6 +1471,7 @@ par_funcdef(void) if (num == 0) { /* Anonymous function, possibly with arguments */ incmdpos = 0; + *complex = 1; } zshlex(); } else if (unset(SHORTLOOPS)) { @@ -1735,6 +1736,7 @@ par_simple(int *complex, int nr) if (argc == 0) { /* Anonymous function, possibly with arguments */ incmdpos = 0; + *complex = 1; } zshlex(); } else { Index: Test/D03procsubst.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D03procsubst.ztst,v retrieving revision 1.6 diff -p -u -r1.6 D03procsubst.ztst --- Test/D03procsubst.ztst 17 Aug 2011 20:26:05 -0000 1.6 +++ Test/D03procsubst.ztst 21 Dec 2012 10:20:59 -0000 @@ -88,3 +88,22 @@ print something=${:-=(echo 'C,D),(F,G)'} 1: Graceful handling of bad substitution in enclosed context ?(eval):1: unterminated `=(...)' + + () { + print -n "first: " + cat $1 + print -n "second: " + cat $2 + } =(echo This becomes argument one) =(echo and this argument two) + function { + print -n "third: " + cat $1 + print -n "fourth: " + cat $2 + } =(echo This becomes argument three) =(echo and this argument four) +0:Process environment of anonymous functions +>first: This becomes argument one +>second: and this argument two +>third: This becomes argument three +>fourth: and this argument four + -- Peter Stephenson Consultant, Software Tel: +44 (0)1223 434724 Samsung Cambridge Solution Centre St John's House, St John's Innovation Park, Cowley Road, Cambridge, CB4 0ZT, UK