Am 15.03.2017 um 10:44 schrieb Zenobiusz Kunegunda:
$ git bisect bad
7333ed1788b4f2b162a35003044d77a716732a1f is the first bad commit
commit 7333ed1788b4f2b162a35003044d77a716732a1f
Author: René Scharfe <l....@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é

Reply via email to