Subject: Re: [BUG] Directory glob picks up running or already-run scripts on OS X
From: Bart Schaefer <[email-masked]>
To: [email-masked]
Date: Sun, 10 Jul 2016 21:58:21 -0700
List-Id: Zsh Workers List <zsh-workers.zsh.org>

I'm not sure whether this was introduced when adding the (Y) qualifier,
or if it was already lurking.  With the following DPUTS() added and zsh
compiled with debugging, Test/D02glob.ztst will fail (on any platform).

diff --git a/Src/glob.c b/Src/glob.c
index 2051016..5260b63 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -318,6 +318,8 @@ insert(char *s, int checked)
     char *news = s;
     int statted = 0;
 
+    DPUTS(!s || !*s, "BUG: adding empty string as glob match");
+
     queue_signals();
     inserts = NULL;

The problem seems to be that scanner() calls recursively one extra
time when looking at "notadirectory/".

In that case statfullpath("") is called and, for reasons I haven't
figured out, that returns success on MacOS when called in exactly
the circumstances that Zhiming describes.

This will eventually correct itself, which leads me to suspect it has
something to do with re-using the global static "pathbuf".

The simple fix would be for insert() to be a no-op when called on the
empty string, but it might be useful to examine scanner() in more
detail to try to avoid the extra recursion.