]> git.ipfire.org Git - thirdparty/git.git/commit
setup: don't die if realpath(3) fails on getcwd(3)
authorKevin Locke <kevin@kevinlocke.name>
Tue, 24 May 2022 19:20:12 +0000 (13:20 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 May 2022 05:08:31 +0000 (22:08 -0700)
commitc37c6dc6a79a1ca7b9d4fa4efd788d8f5ec6369a
tree394f9a49cc674fc27ff5855d9df462b0a42c64cc
parent7a3eb286977746bc09a5de7682df0e5a7085e17c
setup: don't die if realpath(3) fails on getcwd(3)

Prior to Git 2.35.0, git could be run from an inaccessible working
directory so long as the git repository specified by options and/or
environment variables was accessible.  For example:

    git init repo
    mkdir -p a/b
    cd a/b
    chmod u-x ..
    git -C "${PWD%/a/b}/repo" status

If this example seems a bit contrived, consider running with the
repository owner as a substitute UID (e.g. with runuser(1) or sudo(8))
without ensuring the working directory is accessible by that user.

The code added by e6f8861bd4 ("setup: introduce
startup_info->original_cwd") to preserve the working directory attempts
to normalize the path using strbuf_realpath().  If that fails, as in the
case above, it is treated as a fatal error.

This commit treats strbuf_realpath() errors as non-fatal.  If an error
occurs, setup_original_cwd() will continue without applying removal
prevention for cwd, resulting in the pre-2.35.0 behavior.  The risk
should be minimal, since git will not operate on a repository with
inaccessible ancestors, this behavior is only known to occur when cwd is
a descendant of the repository, an ancestor of cwd is inaccessible, and
no ancestors of the repository are inaccessible.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c