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

Running 'type' causes false positive hashed command completion



$ zsh -f
% cd $(mtemp -d)
% touch sudofoo; chmod +x $_
% ./sudo<TAB>
<becomes>
% ./sudofoo <^C>
% type -w ./sudo
./sudo: none
% ./sudo<TAB>
./sudo    sudofoo*

That's wrong because ./sudo does not exist.  However, it's hashed:

% print $commands[./sudo]
/usr/bin/./sudo

To confuse matters further, even though "./sudo" is hashed, a subsequent
'type -w ./sudo' will print "none", because the hash node lacks the
HASHED bit in its .flags and the PATH_DIRS option is unset by default.

Backtrace:

(gdb) 
890         cmdnamtab->addnode(cmdnamtab, ztrdup(arg0), cn);
(gdb) p arg0
$5 = 0x7ffff7ff2590 "./sudo"
(gdb) bt
#0  hashcmd (arg0=0x7ffff7ff2590 "./sudo", pp=0x7a3f98) at exec.c:890
#1  0x0000000000421507 in findcmd (arg0=0x7ffff7ff2590 "./sudo", docopy=1) at exec.c:776
#2  0x000000000041382c in bin_whence (nam=0x7ffff7ff2580 "type", argv=0x7ffff7ff25a0, ops=0x7fffffffda50, func=0) at builtin.c:3642
#3  0x0000000000407702 in execbuiltin (args=0x7ffff7ff2520, assigns=0x0, bn=0x76ed00 <builtins+4032>) at builtin.c:484
#4  0x000000000042a0e9 in execcmd (state=0x7fffffffe490, input=0, output=0, how=18, last1=1) at exec.c:3660
#5  0x00000000004246be in execpline2 (state=0x7fffffffe490, pcode=131, how=18, input=0, output=0, last1=1) at exec.c:1758
#6  0x000000000042360d in execpline (state=0x7fffffffe490, slcode=5122, how=18, last1=1) at exec.c:1536
#7  0x0000000000422a43 in execlist (state=0x7fffffffe490, dont_change_job=0, exiting=1) at exec.c:1294
#8  0x0000000000422297 in execode (p=0x7ffff7ff24b0, dont_change_job=0, exiting=1, context=0x53acd2 "cmdarg") at exec.c:1085
#9  0x000000000042216f in execstring (s=0x7fffffffe9c5 "type -w ./sudo", dont_change_job=0, exiting=1, context=0x53acd2 "cmdarg") at exec.c:1051
#10 0x00000000004460b9 in init_misc (cmd=0x7fffffffe9c5 "type -w ./sudo", zsh_name=0x7fffffffe9be "zsh") at init.c:1289
#11 0x00000000004478fb in zsh_main (argc=3, argv=0x7fffffffe688) at init.c:1673
#12 0x0000000000406a96 in main (argc=3, argv=0x7fffffffe688) at ./main.c:93

Originally reported as https://github.com/zsh-users/zsh-syntax-highlighting/issues/354.



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