zsh-workers
 help / color / mirror / code / Atom feed
From: Charles Blake <charlechaud@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: Command hashing/autocd bug & possible fixes
Date: Mon, 18 Mar 2019 17:20:58 -0400	[thread overview]
Message-ID: <CAKiz1a_R+kjw-K8xWDmdBNFswywztBDvPPYjiXqkpKCHuA7LuA@mail.gmail.com> (raw)
In-Reply-To: <1552903309.5658.4.camel@samsung.com>

[-- Attachment #1: Type: text/plain, Size: 2954 bytes --]

>This certainly looks plausible.  I can't offhand think of a reason why a
>hashed command would begin with a "/"; it's just asking for trouble.

Cool.  I think stricter/cleaner cmdnamtab is safer long-term.  Not sure
any users will complain about 'hash' built-in no longer saving absolute
keys which is a consequence of your preferred resolution, but that's
only likely to be short-term, if it exists at all.

You likely want to document that in the man page or at least release
notes so that any 'hash' users aren't mystified.  Also, you may want
to double check other possible ways cmdnamtab can be poisoned.  greping
for addnode.cmdname, I think the only other spot is Modules/parameter.c
but parameter names cannot have dots and slashes anyway.

I haven't analyzed it -- the code is so twisty and FS state dependence
as well as all the setopt stuff is a lot of cases -- but it's at least
conceivable that user-inserted *relative* paths in cmdnamtab can break
something (maybe a feature other than AUTOCD or some future feature).
There may be no good reason to have explicitly relative paths starting
with "./" or "../" in there either.  You may also want to expand your
preferred solution to cover those.  PATH-relative entries can make
sense.  Eg., mh/inc for those old school enough to recall /usr/bin/mh
installations.

So, I'd stop short of a "block *any* '/' in cmdnamtab keys" rule.
Testing just the start of the string is faster anyway.  Presently,
neither the explicitly relative (which don't make sense to cache) nor
PATH-relative entries (which do make sense to cache) get in cmdnamtab
automatically unless I'm missing something.  They can be put manually
via 'hash', though, and PATH-relative profitably so (a dubiously small
profit, but still).  If they do cause trouble it's "likely" users know
they did it by hacking search with 'hash'..Probably very rare if it's
even a problem at all.  All famous last words, though.  Some under-
the-covers package might do it for them.

Indeed, running whence on absolute paths has to be rare, too.  I only
noticed it recently using zsh-syntax-highlighting which broke AUTOCD on
just a couple root dirents..mysteriously at first.  I didn't realize it
was z-sy-h for a while.  Then it took a short while to isolate it to
just entries in my $PATH.  Then I just disabled z-sy-h for *just* long
enough to forget why I disabled it.  Re-trying z-sy-h a few days ago
reminded me.  I figured I should report this time since last time I
forgot.  Matthew Martin quickly reduced the misbehavior to whence with
Daniel doing an easy subshell fix to avoid poisoning longer-term state.

Curious just how long this bug lurked, I tested old versions of Zsh.
I had to go all the way back to zsh2.1 from circa 1993 to find a
version *without* this bug.  zsh2.0 also worked.  I think 2.0 may have
been the first release with AUTOCD.  At least zsh-1.0 didn't have it.
So, well, it worked for a little while, anyway. ;-)

      reply	other threads:[~2019-03-18 21:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190316200339epcas3p2370800b4409cedfc025ef1c972334aa7@epcas3p2.samsung.com>
2019-03-16 20:01 ` Charles Blake
2019-03-18 10:01   ` Peter Stephenson
2019-03-18 21:20     ` Charles Blake [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKiz1a_R+kjw-K8xWDmdBNFswywztBDvPPYjiXqkpKCHuA7LuA@mail.gmail.com \
    --to=charlechaud@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).