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

Re: [Bug] Strange Globing Behaviour when used with sudo



On Thu, May 31, 2018 at 04:29:39PM +0100, Peter Stephenson wrote:
> On Thu, 31 May 2018 20:39:45 +0900
> Jun T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
> > If we want to workaround this "bug", we need to check st_mode of dummy
> > somewhere in glob.c.
> 
> The key point is probably the return from statfullpath(), but as far as
> ad-hoc workarounds go you're on your own, I'm afraid.
> 

I came up with a patch, but it's more a proof of concept. It fixes the
issue at hand, but I am not sure about it's side effects so I didn't
clean it up.
What is happening is the following: the problem arises when
statfullpath is called in glob.c at the following place:

} else if (!checked) {
	if (statfullpath(s, &buf, 1)) {
		unqueue_signals();
		return;
	}

As s is NULL and buf is in the example ./file/, statfullpath adds to
buf a . so that it's "./file/.". At the end of the function stat is
called for this path, which should return a non-zero value, but which
doesn't happen with sudo on Mac OS X. Instead it returns incorrectly
zero, which is then the return value of statfullpath, and thus
                unqueue_signals();
		return;
isn't called, and we get matches. So one possibility to fix this is to
call stat before adding the . to ./file/, and the return non-zero if
it is not a directory. But again, I don't know whether this fix would
introduce some other bugs. I'm also not sure whether there are even
more "bugs" because Mac OS behaves so strangely with sudo. 

--
Best,
Daniel

diff --git a/Src/glob.c b/Src/glob.c
index 66a95329f..19a8766f9 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -294,6 +294,8 @@ statfullpath(const char *s, struct stat *st, int
l)
         * Don't add the '.' if the path so far is empty, since
         * then we get bogus empty strings inserted as files.
         */
+        stat(buf, st);
+        return !S_ISDIR(st->st_mode);
	 buf[pathpos - pathbufcwd] = '.';
	 buf[pathpos - pathbufcwd + 1] = '\0';
         l = 0;



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