From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6961 invoked by alias); 11 Nov 2016 09:43:22 -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: 39915 Received: (qmail 6539 invoked from network); 11 Nov 2016 09:43:22 -0000 X-Qmail-Scanner-Diagnostics: from out4-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.28):SA:0(-0.7/5.0):. Processed in 1.470719 secs); 11 Nov 2016 09:43:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=ru4Anb5v9hLzDWd 9DluRKQKjQeE=; b=j0W/evXGYAFFXxMC2KuXsz5bZpNXlfdcEaHMQYj10+H3/YY +CQgfBc5ZJ7CwPmuROLPQhl5KUTiOo3LXRO1Qk0XhUFLcsdniLnrUbWexe5Qzydf P0gmaMQI9BZMVjSY+zBCWHovsNg+08sWSDqiUyktmdQ3iW4U2jaiZasTiMno= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=ru4Anb5v9hLzDW d9DluRKQKjQeE=; b=WFt3yMbhKFtnNwY5bb59X+bjQxNuTRxHB5GypGAefpZ4Xj Iucy0bV8eO/cDefHLAZKPoCP9MX+H1fv7GhxDVjfTpuqQlg298dj7DSuk6GaXMtC KIILavk9iEFA/T/UEzgw6mBTBh4BIeDWOuMbM7VUZWFSjT/Oe0es3goiHl/fM= X-ME-Sender: X-Sasl-enc: D8D0qiYZQ7Awo38cjE6FyX3uy+gfrtwb+Wgp/CNN9VRA 1478857395 Date: Fri, 11 Nov 2016 09:41:01 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: Re: Running 'type' causes false positive hashed command completion Message-ID: <20161111094101.GA3967@fujitsu.shahaf.local2> References: <20160824205849.GA11450@fujitsu.shahaf.local2> <160825095900.ZM16562@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline In-Reply-To: <160825095900.ZM16562@torch.brasslantern.com> User-Agent: Mutt/1.5.23 (2014-03-12) --J/dobhs11T7y2rNN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Bart Schaefer wrote on Thu, Aug 25, 2016 at 09:59:00 -0700: > On Aug 24, 8:58pm, Daniel Shahaf wrote: > } Subject: Running 'type' causes false positive hashed command completion > } > } $ zsh -f > } % cd $(mtemp -d) > } % touch sudofoo; chmod +x $_ > } % ./sudo > } > } % ./sudofoo <^C> > } % type -w ./sudo > } ./sudo: none > } % ./sudo > } ./sudo sudofoo* > } > } That's wrong because ./sudo does not exist. > > This seems pretty obvious: > > > diff --git a/Src/exec.c b/Src/exec.c > index ea9214d..9b24d38 100644 > --- a/Src/exec.c > +++ b/Src/exec.c > @@ -772,7 +772,7 @@ findcmd(char *arg0, int docopy) > - if (!cn && isset(HASHCMDS)) > + if (!cn && isset(HASHCMDS) && !isrelative(arg0)) > cn = hashcmd(arg0, path); > > Can anyone think of a valid case which that breaks? The doc (under the > PATH_DIRS option) even says "Commands explicitly beginning with `/', `./' > or `../' are not subject to the path search." I've just noticed another bug (predates this patch): % setopt pathdirs % ./pwd zsh: no such file or directory: ./pwd % type ./pwd ./pwd is /bin/./pwd That's wrong, 'type' should have returned 'none'. Patch attached. Cheers, Daniel --J/dobhs11T7y2rNN Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-whence-Honor-PATH_DIRS-option-for-arguments-that-sta.patch" >>From d69ba249faeab0e6edb95062482d4f59fde01039 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 11 Nov 2016 02:25:21 +0000 Subject: [PATCH] whence: Honor PATH_DIRS option for arguments that start with './' or '../'. While here, add some docstrings. --- Src/exec.c | 23 ++++++++++++++++------- Test/E01options.ztst | 4 ++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Src/exec.c b/Src/exec.c index a01a633..ad80dd0 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -806,14 +806,13 @@ findcmd(char *arg0, int docopy, int default_path) cn = hashcmd(arg0, path); if ((int) strlen(arg0) > PATH_MAX) return NULL; - for (s = arg0; *s; s++) - if (*s == '/') { - RET_IF_COM(arg0); - if (arg0 == s || unset(PATHDIRS)) { - return NULL; - } - break; + if ((s = strchr(arg0, '/'))) { + RET_IF_COM(arg0); + if (arg0 == s || unset(PATHDIRS) || !strncmp(arg0, "./", 2) || + !strncmp(arg0, "../", 3)) { + return NULL; } + } if (cn) { char nn[PATH_MAX]; @@ -848,6 +847,11 @@ findcmd(char *arg0, int docopy, int default_path) return NULL; } +/* + * Return TRUE if the given path denotes an executable regular file, or a + * symlink to one. + */ + /**/ int iscom(char *s) @@ -877,6 +881,11 @@ isreallycom(Cmdnam cn) return iscom(fullnam); } +/* + * Return TRUE if the given path contains a dot or dot-dot component + * and does not start with a slash. + */ + /**/ int isrelative(char *s) diff --git a/Test/E01options.ztst b/Test/E01options.ztst index 40e96af..45df9f5 100644 --- a/Test/E01options.ztst +++ b/Test/E01options.ztst @@ -784,6 +784,10 @@ >unsetting option... ?(eval):14: no such file or directory: pathtestdir/findme + (setopt pathdirs; path+=( /usr/bin ); type ./env) +1:whence honours PATH_DIRS option +>./env not found + setopt posixbuiltins PATH= command -v print PATH= command -V print --J/dobhs11T7y2rNN--