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

Re: fatal: Could not get current working directory: Permission denied | affected 2.10,2.11,2.12, but not 1.9.5 |

From
René Scharfe <l.s.r@web.de>
Date
Mar 17, 2017, 22:50 UTC
Message-ID
<d27d4fd1-8069-ec53-df3f-c3e176f83f16@web.de>
In-Reply-To
<20170317222902.isndsmzy43btxh4i@sigill.intra.peff.net>
Am 17.03.2017 um 23:29 schrieb Jeff King:
Show 30 quoted lines
> On Fri, Mar 17, 2017 at 10:07:18PM +0100, René Scharfe wrote:
>
>>>   As  an extension to the POSIX.1-2001 standard, Linux (libc4, libc5,
>>> glibc) getcwd()
>>>   allocates the buffer dynamically using malloc(3) if buf is NULL.  In
>>> this case, the
>>>   allocated buffer has the length size unless size is zero, when buf
>>> is allocated as big
>>>   as necessary.  The caller should free(3) the returned buffer.
>>>
>>> This sounds specific to Linux (though I am reading Linux man pages,
>>> which claim this; Also it seems I might have misread it as it also states
>>> "The pathname is returned as the function result and via the
>>> argument buf, if present.").
>>
>> I'm only interested in FreeBSD for now, as that's the platform Zenobiusz
>> reported the issue on and I haven't been able to reproduce it, so this is
>> still a bit exploratory, but hopefully getting closer.  This extension is
>> used in the first version of pwd(1) in FreeBSD's repo, comitted 1994-05-26,
>> so it was supported there basically forever.
>>
>> The oldest version I found that's using the extention is NetBSD's pwd(1),
>> which was committed 1993-03-21 and carries a SCCS timestamp of 1991-02-20.
>> Visual Studio .NET 2003 supports it as well.
>
> My big question is what happens on other platforms when they see a NULL
> (but 0-sized) buffer. Any reasonable implementation would just return
> ERANGE and we'd fall back to the existing code. But we often have to deal with unreasonable ones.
>
> So do we need a "my OS understands getcwd(NULL)" build knob?

POSIX specifies the behavior in this case as unspecified. An implementation could offer a different extension, and e.g. return a pointer to a static buffer. So the answer would probably be "yes" if this was a patch meant for public consumption. For now it's only compatible with BSDs, Windows, MacOSX, Linux. :)

René
Previous: Jeff KingNext: Zenobiusz Kunegunda
Message 18 of 23 in “fatal: Could not get current working directory: Permission denied | affected 2.10,2.11,2.12, but not 1.9.5 |”
  1. Zenobiusz KunegundaMar 6, 2017
  2. René ScharfeMar 8, 2017
  3. Zenobiusz KunegundaMar 9, 2017
  4. René ScharfeMar 11, 2017
  5. Zenobiusz KunegundaMar 13, 2017
  6. René ScharfeMar 13, 2017
  7. Zenobiusz KunegundaMar 14, 2017
  8. Zenobiusz KunegundaMar 13, 2017
  9. René ScharfeMar 13, 2017
  10. Zenobiusz KunegundaMar 14, 2017
  11. René ScharfeMar 14, 2017
  12. Zenobiusz KunegundaMar 15, 2017
  13. René ScharfeMar 15, 2017
  14. René ScharfeMar 17, 2017
  15. Stefan BellerMar 17, 2017
  16. René ScharfeMar 17, 2017
  17. Jeff KingMar 17, 2017
  18. René ScharfeMar 17, 2017
  19. Zenobiusz KunegundaMar 21, 2017
  20. René ScharfeMar 21, 2017
  21. Zenobiusz KunegundaMar 22, 2017
  22. Zenobiusz KunegundaMar 21, 2017
  23. Zenobiusz KunegundaMar 9, 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.