Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [Bug] Strange Globing Behaviour when used with sudo
- X-seq: zsh-workers 42906
- From: Daniel Tameling <tamelingdaniel@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [Bug] Strange Globing Behaviour when used with sudo
- Date: Thu, 31 May 2018 20:15:46 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=gHVBxVmx1HfXfVddZd8MTCv9MRuqvR958OgkHmY8u5U=; b=l5u3lOzoqN3uElcyyR4ZdDv//Ob4su+71HbnL8VM1WOwBDZdywEVw8+8EiuAP9IhAT cH7yQk2VM8ajK8MgXNVVZ55xF+LDagsrKzqJSCEz57xErn7f5cspMmnPVPbVySqJ6YYN BzzNh8UHAXLrGWH+5CmQBH6zdvyUuJ/m6O+JDWooycTGEPdnWA8uby1QLVbjsDAYN2W5 9cGsfxS/lbkS5l4Eoo6q63vcHWCTGopmQF4QHvX4kg2qZ6lG0owugbX8fRENq1KXKnjc E0ahhxRP7sOqy7qC7zAy3CK8EFZRPbHL9dfmsH31fHyNiiMSyXlsgtEN1sFZvW31Vmh/ AchA==
- In-reply-to: <20180531152941eucas1p2c45927fa47f727224e2da98b4f6a7604~zxFgS-BM50307003070eucas1p2G@eucas1p2.samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAH+w=7YxodoKJhA9-xswA5H7vckiHHzFTO_MqR5Ahux0p3h6NQ@mail.gmail.com> <1527707719.3469997.1390875592.73AD29B6@webmail.messagingengine.com> <20180530202349.GA10754@osmium.lan> <CAMaoPXzzuRvAn1FFF3BJ0fnJTiaGgeg2TJKAZgL4RLwV5t5RBw@mail.gmail.com> <CGME20180530205013epcas1p21e3a53e151d3696ad475913d56ced3db@epcas1p2.samsung.com> <CAMaoPXwFdVPszgra5busqtLNqAKsJxDV56LPW9ZrtUbg=tbSMQ@mail.gmail.com> <20180531094403.05b62bee@camnpupstephen.cam.scsc.local> <20180531084938eucas1p19a854d9e9ea17428cd6549f56a283356~zroN76sl33019130191eucas1p1K@eucas1p1.samsung.com> <3977A049-90E6-4EDD-9E4C-8D2FF38593A3@kba.biglobe.ne.jp> <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@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