Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Command hashing/autocd bug & possible fixes
- X-seq: zsh-workers 44143
- From: Charles Blake <charlechaud@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Command hashing/autocd bug & possible fixes
- Date: Mon, 18 Mar 2019 17:20:58 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Q9vCABblp/rWzdneP0z+kEQF7azxut7GPiupYqMTTxg=; b=HBSsC5J5CYOu98m4DgycO181ogXW2jOke4c58P7OqNVqjpCkpfJKIQgsSiIhLizX9P JSCY6GAseBTFZR3ZD9PAXC0to9858Q+/nvL+bJ/hiBk4+2WH9TTV8COa+njxkFHct6Al KeRlP799h87cqDJKsr7C3NwsXNZgC8rlDKAV/35kIna9ecCrA1YGNAsNOuBHOa8hN48e 19MzHXP1lxRwckkBzV/PCMty64uLzGnt6u0YRSx+aJW+msCkOOXYfUN8aNYCn2ru0/uy 4ZEm/LRo8p6kYVVRJKNmRM6QAhc5mQRd79vYA32txptfl808njL1p453HgF4s6ZS+Fgn yo6Q==
- In-reply-to: <1552903309.5658.4.camel@samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20190316200339epcas3p2370800b4409cedfc025ef1c972334aa7@epcas3p2.samsung.com> <CAKiz1a8Y9HRpBfCF3sL_bvVHJZoAie9OOwcoqANy5i9DviA_cQ@mail.gmail.com> <1552903309.5658.4.camel@samsung.com>
>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. ;-)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author