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

PATCH: fix check for when to hash commands



---

Dana noticed that commands looked up in $commands weren't actually
getting hashed by my findcmd() call, turns out that it checks that the
commands aren't "relative" before calling hashcmd() which then in turn
immediately returns if they are "absolute". The problem here is that the
terms "relative" and "absolute" are relatively non-absolute themselves.

The check we want for findcmd() is not exactly the same as
isrelative()'s only other caller, hashdir(), so open code the check we
do want in hashcmd() instead and stop calling isrelative() in findcmd()

The hunk that removes the !isrelative check is a revert of 39104 but the
hunk in hashcmd() ensures the problem in that thread doesn't reoccur.

Also includes a test written by Dana for the original case of looking up
commands with HASHLISTALL unset, I'll commit that with the other patch,
not this one.

 Src/exec.c             |  4 ++--
 Test/V06parameter.ztst | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index f5ada6585b..366220e764 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -933,7 +933,7 @@ findcmd(char *arg0, int docopy, int default_path)
 	return NULL;
     }
     cn = (Cmdnam) cmdnamtab->getnode(cmdnamtab, arg0);
-    if (!cn && isset(HASHCMDS) && !isrelative(arg0))
+    if (!cn && isset(HASHCMDS))
 	cn = hashcmd(arg0, path);
     if ((int) ztrlen(arg0) >= PATH_MAX)
 	return NULL;
@@ -1051,7 +1051,7 @@ hashcmd(char *arg0, char **pp)
     char *s, buf[MAXCMDLEN];
     char **pq;
 
-    if (*arg0 == '/')
+    if ((*arg0 == '/') || !strncmp(arg0, "./", 2) || !strncmp(arg0, "../", 3))
         return NULL;
     for (; *pp; pp++)
 	if (**pp == '/') {
diff --git a/Test/V06parameter.ztst b/Test/V06parameter.ztst
index 27d587852d..c1f47a9dc1 100644
--- a/Test/V06parameter.ztst
+++ b/Test/V06parameter.ztst
@@ -92,6 +92,25 @@
 >foo
 >bar
 
+  for 1 in hash_cmds no_hash_cmds; do
+    (
+      setopt no_hash_list_all $1
+      : > ls
+      chmod +x ls
+      rm=$commands[rm]
+      path=( $PWD )
+      rehash
+      a=$commands[ls]
+      $rm ls
+      b=$commands[ls]
+      [[ $a == $b ]]
+      print -r - $? $a:$b
+    )
+  done
+-:workers/54617: $commands look-up with no_hash_list_all
+*>0 */ls:*/ls
+*>1 */ls:
+
 %clean
 
  rm -f autofn functrace.zsh rocky3.zsh sourcedfile myfunc
-- 
2.38.1





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