From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1507 invoked from network); 19 Aug 2004 07:14:00 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 19 Aug 2004 07:14:00 -0000 Received: (qmail 96054 invoked from network); 19 Aug 2004 07:13:53 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 07:13:53 -0000 Received: (qmail 12356 invoked by alias); 19 Aug 2004 07:13:11 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7883 Received: (qmail 12346 invoked from network); 19 Aug 2004 07:13:10 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 19 Aug 2004 07:13:10 -0000 Received: (qmail 93857 invoked from network); 19 Aug 2004 07:11:12 -0000 Received: from moonbase.zanshin.com (64.84.47.139) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 07:11:09 -0000 Received: from toltec.zanshin.com (toltec.zanshin.com [64.84.47.166]) by moonbase.zanshin.com (8.12.11/8.12.11) with ESMTP id i7J7B7HU019946 for ; Thu, 19 Aug 2004 00:11:07 -0700 Date: Thu, 19 Aug 2004 00:11:07 -0700 (PDT) From: Bart Schaefer Reply-To: zsh-users@sunsite.dk To: zsh-users@sunsite.dk Subject: Re: Using 'command -v' in a shellscript results in a coredump In-Reply-To: <2004-08-19T01-13-05@devnull.michael-prokop.at> Message-ID: References: <2004-08-19T01-13-05@devnull.michael-prokop.at> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-1.4 required=6.0 tests=BAYES_20 autolearn=no version=2.63 X-Spam-Hits: -1.4 On Thu, 19 Aug 2004, Michael Prokop wrote: > #!/bin/sh > command -v blub > /dev/null 2>&1 > > Running it results in 'zsh: segmentation fault (core dumped)'. The following prevents the core dump without producing any errors from "make test", but I suspect there's something deeper that should be fixed instead. The crash happens whenever 'command -v' or 'command -V' is used with the POSIXBUILTINS option set. The problem is that the code in execcmd() near line 1848 assigns 'hn' to point at the special 'commandbn' struct, but then 1952 is reached and tries (again) to find the builtin named "command" which fails. Nothing picks up the error after that and a null 'hn' is eventually dereferenced by execbuiltin(). Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.69 diff -u -r1.69 exec.c --- Src/exec.c 29 Jul 2004 15:09:51 -0000 1.69 +++ Src/exec.c 19 Aug 2004 07:03:43 -0000 @@ -1949,7 +1949,7 @@ is_shfunc = 1; break; } - if (!(hn = builtintab->getnode(builtintab, cmdarg))) { + if (!hn && !(hn = builtintab->getnode(builtintab, cmdarg))) { if (cflags & BINF_BUILTIN) { zwarn("no such builtin: %s", cmdarg, 0); lastval = 1;