git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] strbuf: support long paths w/o read rights in strbuf_getcwd() on FreeBSD

From
Christian Couder <christian.couder@gmail.com>
Date
Mar 29, 2017, 04:54 UTC
Message-ID
<CAP8UFD1wqW221qxWqMz1jHxDLKCg71a2VBh+wUdV8sMSEN2aZw@mail.gmail.com>
In-Reply-To
<20170328214930.bj4etqn5qecv45im@sigill.intra.peff.net>
On Tue, Mar 28, 2017 at 11:49 PM, Jeff King <peff@peff.net> wrote:
Show 37 quoted lines
> On Tue, Mar 28, 2017 at 11:15:12PM +0200, Christian Couder 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);
>
> I think the main reason is just that we do not have to pay the price to
> allocate PATH_MAX-sized buffers when they are rarely used.
>
> I doubt it matters all that much in practice, though.
Yeah, I can understand that.

But I also wonder if René's patch relies on PATH_MAX being a multiple of 128 on FreeBSD and what would happen for a path between 129 and PATH_MAX if PATH_MAX was something like 254.

Previous: Jeff KingNext: René Scharfe
Message 9 of 10 in “strbuf: support long paths w/o read rights in strbuf_getcwd() on FreeBSD”
  1. strbuf: support long paths w/o read rights in strbuf_getcwd() on FreeBSDRené Scharfe, Mar 26, 2017
  2. Junio C HamanoMar 27, 2017
  3. Zenobiusz KunegundaMar 27, 2017
  4. Junio C HamanoMar 27, 2017
  5. Christian CouderMar 28, 2017
  6. Stefan BellerMar 28, 2017
  7. Christian CouderMar 28, 2017
  8. Jeff KingMar 28, 2017
  9. Christian CouderMar 29, 2017
  10. René ScharfeMar 30, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.