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
ZKZenobiusz Kunegunda <zenobiusz.kunegunda@interia.pl>
Date
Mar 21, 2017, 10:08 UTC
Message-ID
<xiszmpcvkgewmkltlhqf@qpcy>
In-Reply-To
<7f25def4-9943-ae59-a649-b4348a79890e@web.de>
Od: "René Scharfe" &lt;l.s.r@web.de>
Do: "Zenobiusz Kunegunda" &lt;zenobiusz.kunegunda@interia.pl>; 
Wysłane: 22:31 Środa 2017-03-15
Temat: Re: fatal: Could not get current working directory: Permission denied | affected 2.10,2.11,2.12, but not 1.9.5 |
Show 78 quoted lines
> 
> > Am 15.03.2017 um 10:44 schrieb Zenobiusz Kunegunda:
>> $ git bisect bad
>> 7333ed1788b4f2b162a35003044d77a716732a1f is the first bad commit
>> commit 7333ed1788b4f2b162a35003044d77a716732a1f
>> Author: René Scharfe 
>> 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 
> 	#include 
> 	#include 
> 	#include 
> 	#include 
> 
> 	int main(int argc, char **argv)
> 	{
> 		char buf[PATH_MAX];
> 		int last_errno = 0;
> 		size_t len;
> 
> 		for (len = 0; len &lt;= 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é
> 
> 
This program produces same errors I get from git in every directory . But no errors at all when run as root. Here is example when run as reular user.
   $ getcwdtest 
   len = 0, errno = 22, Invalid argument
   len = 1, errno = 34, Result too large
   len = 2, errno = 13, Permission denied
   len = 19, errno = 0, No error: 0
   $ mkdir testdir
   $ cd testdir/
   $ getcwdtest 
   len = 0, errno = 22, Invalid argument
   len = 1, errno = 34, Result too large
   len = 9, errno = 13, Permission denied
   len = 27, errno = 0, No error: 0
But when run as root there is no permission denied errors. Filesystem is ZFS.
Previous: Zenobiusz KunegundaNext: Zenobiusz Kunegunda
Message 22 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.