Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Command hashing/autocd bug & possible fixes



On Sat, 2019-03-16 at 16:01 -0400, Charles Blake wrote:
> Another possible fix might be to try to stop hashcmd from entering
> keys with a leading '/' (or accept an allowRooted parameter).  The
> easiest way to do that..
> 
> diff --git a/Src/exec.c b/Src/exec.c
> index 042ba065a..79ef83c1e 100644
> --- a/Src/exec.c
> +++ b/Src/exec.c
> @@ -940,6 +940,8 @@ hashcmd(char *arg0, char **pp)
>      char *s, buf[PATH_MAX+1];
>      char **pq;
> 
> +    if (*arg0 == '/')
> +        return NULL;
>      for (; *pp; pp++)
>         if (**pp == '/') {
>             s = buf;

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.

We've been confusingly lax about this sort of thing in other places ---
for example, autoload of a function beginning with a "/" used to do path
look up under $fpath, though for a couple of years now has been treated
as an absolute path.

Unless anyone comes up with a counterexample I think I'll put this in.

Thanks for the work.
pws




Messages sorted by: Reverse Date, Date, Thread, Author