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 15, 2017, 21:30 UTC
Message-ID
<7f25def4-9943-ae59-a649-b4348a79890e@web.de>
In-Reply-To
<ffntuqzgjgcfhebokbty@eduj>
Am 15.03.2017 um 10:44 schrieb Zenobiusz Kunegunda:
Show 7 quoted lines
> $ git bisect bad
> 7333ed1788b4f2b162a35003044d77a716732a1f is the first bad commit
> commit 7333ed1788b4f2b162a35003044d77a716732a1f
> Author: René Scharfe <l.s.r@web.de>
> Date:   Mon Jul 28 20:26:40 2014 +0200
>
>     setup: convert setup_git_directory_gently_1 et al. to strbuf

That's what I half-suspected, and I think by now I got an idea. Here's a test program:

	#include <errno.h>
	#include <limits.h>
	#include <stdio.h>
	#include <string.h>
	#include <unistd.h>
	int main(int argc, char **argv)
	{
		char buf[PATH_MAX];
		int last_errno = 0;
		size_t len;
		for (len = 0; len <= PATH_MAX; len++) {
			errno = 0;
			getcwd(buf, len);
			if (errno != last_errno) {
				printf("len = %lu, errno = %d, %s\n",
					len, errno, strerror(errno));
			}
			last_errno = errno;
		}
		return 0;
	}

It runs getcwd(2) with buffer sizes from 0 to PATH_MAX and reports when the error code changes along the way. Let's call it test_getcwd. And here's what I get on FreeBSD 10.3:

	$ mkdir /tmp/a
	$ cd /tmp/a
	$ chmod 100 /tmp/a
	$ test_getcwd
	len = 0, errno = 22, Invalid argument
	len = 1, errno = 34, Result too large
	len = 7, errno = 0, No error: 0
	$ chmod 000 /tmp/a
	$ test_getcwd
	len = 0, errno = 22, Invalid argument
	len = 1, errno = 34, Result too large
	len = 2, errno = 13, Permission denied
	len = 7, errno = 0, No error: 0

So if we don't have execute permission and our buffer is at least one char long but still too small then we get EACCES (13). If we don't have read permissions and our buffer is big enough then the call succeeds. strbuf_getcwd() expects to get ERANGE (34) and nothing else when the buffer is too small.

I'd say it's a bug in FreeBSD -- reporting permission denied or success based on the size of the supplied buffer makes no sense to me, at least.

The initial buffer size used by strbuf_getcwd() is 128, so you should be fine as long as the absolute path to your repository is shorter than that. You should also be fine if you have execute permissions on the directory.

And here I'm puzzled again -- you probably have sufficient permissions set up for your user, right? What does the test program report for your problematic repository and its parent directories?

René
Previous: Zenobiusz KunegundaNext: René Scharfe
Message 13 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.