From: Christian Couder <christian.couder@gmail.com>
To: Stefan Beller <sbeller@google.com>
Cc: "René Scharfe" <l.s.r@web.de>, "Git List" <git@vger.kernel.org>,
"Zenobiusz Kunegunda" <zenobiusz.kunegunda@interia.pl>,
"Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>
Subject: Re: [PATCH] strbuf: support long paths w/o read rights in strbuf_getcwd() on FreeBSD
Date: Tue, 28 Mar 2017 23:47:48 +0200 [thread overview]
Message-ID: <CAP8UFD3sMyJTkoUccC6hV9peT+q3dKyX=ENpPtgjUx+z01EC5A@mail.gmail.com> (raw)
In-Reply-To: <CAGZ79kaFhrEFFfmBUUM7rc9RftS3cKLcvJe5M8jkwKL=bdemgQ@mail.gmail.com>
On Tue, Mar 28, 2017 at 11:24 PM, Stefan Beller <sbeller@google.com> wrote:
> On Tue, Mar 28, 2017 at 2:15 PM, Christian Couder
> <christian.couder@gmail.com> wrote:
>> On Sun, Mar 26, 2017 at 3:43 PM, René Scharfe <l.s.r@web.de> wrote:
>>> FreeBSD implements getcwd(3) as a syscall, but falls back to a version
>>> based on readdir(3) if it fails for some reason. The latter requires
>>> permissions to read and execute path components, while the former does
>>> not. That means that if our buffer is too small and we're missing
>>> rights we could get EACCES, but we may succeed with a bigger buffer.
>>>
>>> Keep retrying if getcwd(3) indicates lack of permissions until our
>>> buffer can fit PATH_MAX bytes, as that's the maximum supported by the
>>> syscall on FreeBSD anyway. This way we do what we can to be able to
>>> benefit from the syscall, but we also won't loop forever if there is a
>>> real permission issue.
>>
>> Sorry to be late and maybe I missed something obvious, but the above
>> and the patch seem complex to me compared with something like:
>>
>> diff --git a/strbuf.c b/strbuf.c
>> index ace58e7367..25eadcbedc 100644
>> --- a/strbuf.c
>> +++ b/strbuf.c
>> @@ -441,7 +441,7 @@ int strbuf_readlink(struct strbuf *sb, const char
>> *path, size_t hint)
>> int strbuf_getcwd(struct strbuf *sb)
>> {
>> size_t oldalloc = sb->alloc;
>> - size_t guessed_len = 128;
>> + size_t guessed_len = PATH_MAX > 128 ? PATH_MAX : 128;
>>
>> for (;; guessed_len *= 2) {
>> strbuf_grow(sb, guessed_len);
>
> From f22a76e911 (strbuf: add strbuf_getcwd(), 2014-07-28):
> Because it doesn't use a fixed-size buffer it supports
> arbitrarily long paths, provided the platform's getcwd() does as well.
> At least on Linux and FreeBSD it handles paths longer than PATH_MAX
> just fine.
Well René's patch says:
>>> Keep retrying if getcwd(3) indicates lack of permissions until our
>>> buffer can fit PATH_MAX bytes, as that's the maximum supported by the
>>> syscall on FreeBSD anyway.
So it says that FreeBSD syscall doesn't handle paths longer than PATH_MAX.
> So with your patch, we'd still see the original issue for paths > PATH_MAX
> IIUC.
Also, René's patch just adds:
+ if (errno == EACCES && guessed_len < PATH_MAX)
+ continue;
so if the length of the path is > PATH_MAX, then guessed_len will have
to be > PATH_MAX and then René's patch will do nothing.
next prev parent reply other threads:[~2017-03-28 21:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-26 13:43 [PATCH] strbuf: support long paths w/o read rights in strbuf_getcwd() on FreeBSD René Scharfe
2017-03-27 0:40 ` Junio C Hamano
2017-03-27 5:55 ` Zenobiusz Kunegunda
2017-03-27 18:40 ` Junio C Hamano
2017-03-28 21:15 ` Christian Couder
2017-03-28 21:24 ` Stefan Beller
2017-03-28 21:47 ` Christian Couder [this message]
2017-03-28 21:49 ` Jeff King
2017-03-29 4:54 ` Christian Couder
2017-03-30 18:01 ` René Scharfe
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAP8UFD3sMyJTkoUccC6hV9peT+q3dKyX=ENpPtgjUx+z01EC5A@mail.gmail.com' \
--to=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
--cc=sbeller@google.com \
--cc=zenobiusz.kunegunda@interia.pl \
/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://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).