From: Daniel Tameling <tamelingdaniel@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: [Bug] Strange Globing Behaviour when used with sudo
Date: Thu, 31 May 2018 20:15:46 +0200 [thread overview]
Message-ID: <20180531181546.osffv3ysjzaxjfid@Daniels-MacBook-Air.local> (raw)
In-Reply-To: <20180531152941eucas1p2c45927fa47f727224e2da98b4f6a7604~zxFgS-BM50307003070eucas1p2G@eucas1p2.samsung.com>
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@kba.biglobe.ne.jp> 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;
next prev parent reply other threads:[~2018-05-31 18:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-30 17:11 Bengt Brodersen
2018-05-30 18:06 ` Bart Schaefer
2018-05-30 19:15 ` Daniel Shahaf
2018-05-30 20:23 ` Phil Pennock
2018-05-30 20:44 ` Bengt Brodersen
2018-05-30 20:49 ` Bengt Brodersen
2018-05-31 8:44 ` Peter Stephenson
[not found] ` <20180531094403.05b62bee@camnpupstephen.cam.scsc.local>
2018-05-31 8:49 ` Peter Stephenson
2018-05-31 11:39 ` Jun T
2018-05-31 15:29 ` Peter Stephenson
2018-05-31 18:15 ` Daniel Tameling [this message]
2018-06-01 14:08 ` Jun T.
2018-06-02 18:17 ` Daniel Tameling
2018-06-03 16:30 ` Jun T.
2018-06-03 18:48 ` Daniel Tameling
2018-06-03 19:17 ` dana
2018-06-04 1:23 ` Jun T
2018-06-04 12:48 ` Jun T
2018-06-14 12:26 ` Bengt Brodersen
2018-05-31 6:37 ` Martijn Dekker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180531181546.osffv3ysjzaxjfid@Daniels-MacBook-Air.local \
--to=tamelingdaniel@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).