]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
19 months agoSync with 2.34.5
Taylor Blau [Thu, 6 Oct 2022 21:43:37 +0000 (17:43 -0400)] 
Sync with 2.34.5

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoGit 2.34.5 v2.34.5
Taylor Blau [Fri, 30 Sep 2022 21:22:02 +0000 (17:22 -0400)] 
Git 2.34.5

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoSync with 2.33.5
Taylor Blau [Thu, 6 Oct 2022 21:42:55 +0000 (17:42 -0400)] 
Sync with 2.33.5

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoGit 2.33.5 v2.33.5
Taylor Blau [Fri, 30 Sep 2022 21:04:26 +0000 (17:04 -0400)] 
Git 2.33.5

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoSync with 2.32.4
Taylor Blau [Thu, 6 Oct 2022 21:42:02 +0000 (17:42 -0400)] 
Sync with 2.32.4

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoGit 2.32.4 v2.32.4
Taylor Blau [Fri, 30 Sep 2022 21:00:58 +0000 (17:00 -0400)] 
Git 2.32.4

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoSync with 2.31.5
Taylor Blau [Thu, 6 Oct 2022 21:40:44 +0000 (17:40 -0400)] 
Sync with 2.31.5

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoGit 2.31.5 v2.31.5
Taylor Blau [Fri, 30 Sep 2022 20:56:02 +0000 (16:56 -0400)] 
Git 2.31.5

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoSync with 2.30.6
Taylor Blau [Thu, 6 Oct 2022 21:39:15 +0000 (17:39 -0400)] 
Sync with 2.30.6

Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 months agoGit 2.30.6 v2.30.6
Taylor Blau [Fri, 30 Sep 2022 20:32:10 +0000 (16:32 -0400)] 
Git 2.30.6

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot2080: prepare for changing protocol.file.allow
Taylor Blau [Fri, 30 Sep 2022 20:48:56 +0000 (16:48 -0400)] 
t2080: prepare for changing protocol.file.allow

Explicitly cloning over the "file://" protocol in t1092 in preparation
for merging a security release which will change the default value of
this configuration to be "user".

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot1092: prepare for changing protocol.file.allow
Taylor Blau [Fri, 30 Sep 2022 20:47:00 +0000 (16:47 -0400)] 
t1092: prepare for changing protocol.file.allow

Explicitly cloning over the "file://" protocol in t1092 in preparation
for merging a security release which will change the default value of
this configuration to be "user".

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot2080: prepare for changing protocol.file.allow
Taylor Blau [Fri, 30 Sep 2022 20:48:56 +0000 (16:48 -0400)] 
t2080: prepare for changing protocol.file.allow

Explicitly cloning over the "file://" protocol in t1092 in preparation
for merging a security release which will change the default value of
this configuration to be "user".

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot1092: prepare for changing protocol.file.allow
Taylor Blau [Fri, 30 Sep 2022 20:47:00 +0000 (16:47 -0400)] 
t1092: prepare for changing protocol.file.allow

Explicitly cloning over the "file://" protocol in t1092 in preparation
for merging a security release which will change the default value of
this configuration to be "user".

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agoalias.c: reject too-long cmdline strings in split_cmdline()
Kevin Backhouse [Wed, 28 Sep 2022 22:53:32 +0000 (18:53 -0400)] 
alias.c: reject too-long cmdline strings in split_cmdline()

This function improperly uses an int to represent the number of entries
in the resulting argument array. This allows a malicious actor to
intentionally overflow the return value, leading to arbitrary heap
writes.

Because the resulting argv array is typically passed to execv(), it may
be possible to leverage this attack to gain remote code execution on a
victim machine. This was almost certainly the case for certain
configurations of git-shell until the previous commit limited the size
of input it would accept. Other calls to split_cmdline() are typically
limited by the size of argv the OS is willing to hand us, so are
similarly protected.

So this is not strictly fixing a known vulnerability, but is a hardening
of the function that is worth doing to protect against possible unknown
vulnerabilities.

One approach to fixing this would be modifying the signature of
`split_cmdline()` to look something like:

    int split_cmdline(char *cmdline, const char ***argv, size_t *argc);

Where the return value of `split_cmdline()` is negative for errors, and
zero otherwise. If non-NULL, the `*argc` pointer is modified to contain
the size of the `**argv` array.

But this implies an absurdly large `argv` array, which more than likely
larger than the system's argument limit. So even if split_cmdline()
allowed this, it would fail immediately afterwards when we called
execv(). So instead of converting all of `split_cmdline()`'s callers to
work with `size_t` types in this patch, instead pursue the minimal fix
here to prevent ever returning an array with more than INT_MAX entries
in it.

Signed-off-by: Kevin Backhouse <kevinbackhouse@github.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agoshell: limit size of interactive commands
Jeff King [Wed, 28 Sep 2022 22:52:48 +0000 (18:52 -0400)] 
shell: limit size of interactive commands

When git-shell is run in interactive mode (which must be enabled by
creating $HOME/git-shell-commands), it reads commands from stdin, one
per line, and executes them.

We read the commands with git_read_line_interactively(), which uses a
strbuf under the hood. That means we'll accept an input of arbitrary
size (limited only by how much heap we can allocate). That creates two
problems:

  - the rest of the code is not prepared to handle large inputs. The
    most serious issue here is that split_cmdline() uses "int" for most
    of its types, which can lead to integer overflow and out-of-bounds
    array reads and writes. But even with that fixed, we assume that we
    can feed the command name to snprintf() (via xstrfmt()), which is
    stuck for historical reasons using "int", and causes it to fail (and
    even trigger a BUG() call).

  - since the point of git-shell is to take input from untrusted or
    semi-trusted clients, it's a mild denial-of-service. We'll allocate
    as many bytes as the client sends us (actually twice as many, since
    we immediately duplicate the buffer).

We can fix both by just limiting the amount of per-command input we're
willing to receive.

We should also fix split_cmdline(), of course, which is an accident
waiting to happen, but that can come on top. Most calls to
split_cmdline(), including the other one in git-shell, are OK because
they are reading from an OS-provided argv, which is limited in practice.
This patch should eliminate the immediate vulnerabilities.

I picked 4MB as an arbitrary limit. It's big enough that nobody should
ever run into it in practice (since the point is to run the commands via
exec, we're subject to OS limits which are typically much lower). But
it's small enough that allocating it isn't that big a deal.

The code is mostly just swapping out fgets() for the strbuf call, but we
have to add a few niceties like flushing and trimming line endings. We
could simplify things further by putting the buffer on the stack, but
4MB is probably a bit much there. Note that we'll _always_ allocate 4MB,
which for normal, non-malicious requests is more than we would before
this patch. But on the other hand, other git programs are happy to use
96MB for a delta cache. And since we'd never touch most of those pages,
on a lazy-allocating OS like Linux they won't even get allocated to
actual RAM.

The ideal would be a version of strbuf_getline() that accepted a maximum
value. But for a minimal vulnerability fix, let's keep things localized
and simple. We can always refactor further on top.

The included test fails in an obvious way with ASan or UBSan (which
notice the integer overflow and out-of-bounds reads). Without them, it
fails in a less obvious way: we may segfault, or we may try to xstrfmt()
a long string, leading to a BUG(). Either way, it fails reliably before
this patch, and passes with it. Note that we don't need an EXPENSIVE
prereq on it. It does take 10-15s to fail before this patch, but with
the new limit, we fail almost immediately (and the perl process
generating 2GB of data exits via SIGPIPE).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agoshell: add basic tests
Jeff King [Wed, 28 Sep 2022 22:50:36 +0000 (18:50 -0400)] 
shell: add basic tests

We have no tests of even basic functionality of git-shell. Let's add a
couple of obvious ones. This will serve as a framework for adding tests
for new things we fix, as well as making sure we don't screw anything up
too badly while doing so.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agotransport: make `protocol.file.allow` be "user" by default
Taylor Blau [Fri, 29 Jul 2022 19:22:13 +0000 (15:22 -0400)] 
transport: make `protocol.file.allow` be "user" by default

An earlier patch discussed and fixed a scenario where Git could be used
as a vector to exfiltrate sensitive data through a Docker container when
a potential victim clones a suspicious repository with local submodules
that contain symlinks.

That security hole has since been plugged, but a similar one still
exists.  Instead of convincing a would-be victim to clone an embedded
submodule via the "file" protocol, an attacker could convince an
individual to clone a repository that has a submodule pointing to a
valid path on the victim's filesystem.

For example, if an individual (with username "foo") has their home
directory ("/home/foo") stored as a Git repository, then an attacker
could exfiltrate data by convincing a victim to clone a malicious
repository containing a submodule pointing at "/home/foo/.git" with
`--recurse-submodules`. Doing so would expose any sensitive contents in
stored in "/home/foo" tracked in Git.

For systems (such as Docker) that consider everything outside of the
immediate top-level working directory containing a Dockerfile as
inaccessible to the container (with the exception of volume mounts, and
so on), this is a violation of trust by exposing unexpected contents in
the working copy.

To mitigate the likelihood of this kind of attack, adjust the "file://"
protocol's default policy to be "user" to prevent commands that execute
without user input (including recursive submodule initialization) from
taking place by default.

Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/t9NNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:21:53 +0000 (15:21 -0400)] 
t/t9NNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that interact with submodules a handful of times use
`test_config_global`.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/t7NNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:21:40 +0000 (15:21 -0400)] 
t/t7NNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that only need to interact with submodules in a limited capacity
have individual Git commands annotated with the appropriate
configuration via `-c`. Tests that interact with submodules a handful of
times use `test_config_global` instead. Test scripts that rely on
submodules throughout use a `git config --global` during a setup test
towards the beginning of the script.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/t6NNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:21:18 +0000 (15:21 -0400)] 
t/t6NNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that only need to interact with submodules in a limited capacity
have individual Git commands annotated with the appropriate
configuration via `-c`.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/t5NNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:21:06 +0000 (15:21 -0400)] 
t/t5NNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that only need to interact with submodules in a limited capacity
have individual Git commands annotated with the appropriate
configuration via `-c`. Tests that interact with submodules a handful of
times use `test_config_global` instead. Test scripts that rely on
submodules throughout use a `git config --global` during a setup test
towards the beginning of the script.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/t4NNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:20:43 +0000 (15:20 -0400)] 
t/t4NNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that only need to interact with submodules in a limited capacity
have individual Git commands annotated with the appropriate
configuration via `-c`. Tests that interact with submodules a handful of
times use `test_config_global` instead. Test scripts that rely on
submodules throughout use a `git config --global` during a setup test
towards the beginning of the script.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/t3NNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:20:28 +0000 (15:20 -0400)] 
t/t3NNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that only need to interact with submodules in a limited capacity
have individual Git commands annotated with the appropriate
configuration via `-c`. Tests that interact with submodules a handful of
times use `test_config_global` instead. Test scripts that rely on
submodules throughout use a `git config --global` during a setup test
towards the beginning of the script.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/2NNNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:20:03 +0000 (15:20 -0400)] 
t/2NNNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that only need to interact with submodules in a limited capacity
have individual Git commands annotated with the appropriate
configuration via `-c`. Tests that interact with submodules a handful of
times use `test_config_global` instead. Test scripts that rely on
submodules throughout use a `git config --global` during a setup test
towards the beginning of the script.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/t1NNN: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:16:10 +0000 (15:16 -0400)] 
t/t1NNN: allow local submodules

To prepare for the default value of `protocol.file.allow` to change to
"user", ensure tests that rely on local submodules can initialize them
over the file protocol.

Tests that only need to interact with submodules in a limited capacity
have individual Git commands annotated with the appropriate
configuration via `-c`. Tests that interact with submodules a handful of
times use `test_config_global` instead.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agot/lib-submodule-update.sh: allow local submodules
Taylor Blau [Fri, 29 Jul 2022 19:13:58 +0000 (15:13 -0400)] 
t/lib-submodule-update.sh: allow local submodules

To prepare for changing the default value of `protocol.file.allow` to
"user", update the `prolog()` function in lib-submodule-update to allow
submodules to be cloned over the file protocol.

This is used by a handful of submodule-related test scripts, which
themselves will have to tweak the value of `protocol.file.allow` in
certain locations. Those will be done in subsequent commits.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
20 months agobuiltin/clone.c: disallow `--local` clones with symlinks
Taylor Blau [Thu, 28 Jul 2022 21:35:17 +0000 (17:35 -0400)] 
builtin/clone.c: disallow `--local` clones with symlinks

When cloning a repository with `--local`, Git relies on either making a
hardlink or copy to every file in the "objects" directory of the source
repository. This is done through the callpath `cmd_clone()` ->
`clone_local()` -> `copy_or_link_directory()`.

The way this optimization works is by enumerating every file and
directory recursively in the source repository's `$GIT_DIR/objects`
directory, and then either making a copy or hardlink of each file. The
only exception to this rule is when copying the "alternates" file, in
which case paths are rewritten to be absolute before writing a new
"alternates" file in the destination repo.

One quirk of this implementation is that it dereferences symlinks when
cloning. This behavior was most recently modified in 36596fd2df (clone:
better handle symlinked files at .git/objects/, 2019-07-10), which
attempted to support `--local` clones of repositories with symlinks in
their objects directory in a platform-independent way.

Unfortunately, this behavior of dereferencing symlinks (that is,
creating a hardlink or copy of the source's link target in the
destination repository) can be used as a component in attacking a
victim by inadvertently exposing the contents of file stored outside of
the repository.

Take, for example, a repository that stores a Dockerfile and is used to
build Docker images. When building an image, Docker copies the directory
contents into the VM, and then instructs the VM to execute the
Dockerfile at the root of the copied directory. This protects against
directory traversal attacks by copying symbolic links as-is without
dereferencing them.

That is, if a user has a symlink pointing at their private key material
(where the symlink is present in the same directory as the Dockerfile,
but the key itself is present outside of that directory), the key is
unreadable to a Docker image, since the link will appear broken from the
container's point of view.

This behavior enables an attack whereby a victim is convinced to clone a
repository containing an embedded submodule (with a URL like
"file:///proc/self/cwd/path/to/submodule") which has a symlink pointing
at a path containing sensitive information on the victim's machine. If a
user is tricked into doing this, the contents at the destination of
those symbolic links are exposed to the Docker image at runtime.

One approach to preventing this behavior is to recreate symlinks in the
destination repository. But this is problematic, since symlinking the
objects directory are not well-supported. (One potential problem is that
when sharing, e.g. a "pack" directory via symlinks, different writers
performing garbage collection may consider different sets of objects to
be reachable, enabling a situation whereby garbage collecting one
repository may remove reachable objects in another repository).

Instead, prohibit the local clone optimization when any symlinks are
present in the `$GIT_DIR/objects` directory of the source repository.
Users may clone the repository again by prepending the "file://" scheme
to their clone URL, or by adding the `--no-local` option to their `git
clone` invocation.

The directory iterator used by `copy_or_link_directory()` must no longer
dereference symlinks (i.e., it *must* call `lstat()` instead of `stat()`
in order to discover whether or not there are symlinks present). This has
no bearing on the overall behavior, since we will immediately `die()` on
encounter a symlink.

Note that t5604.33 suggests that we do support local clones with
symbolic links in the source repository's objects directory, but this
was likely unintentional, or at least did not take into consideration
the problem with sharing parts of the objects directory with symbolic
links at the time. Update this test to reflect which options are and
aren't supported.

Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
23 months agoGit 2.35.4 v2.35.4
Johannes Schindelin [Thu, 23 Jun 2022 10:36:05 +0000 (12:36 +0200)] 
Git 2.35.4

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23 months agoSync with 2.34.4
Johannes Schindelin [Thu, 23 Jun 2022 10:36:03 +0000 (12:36 +0200)] 
Sync with 2.34.4

* maint-2.34:
  Git 2.34.4
  Git 2.33.4
  Git 2.32.3
  Git 2.31.4
  Git 2.30.5
  setup: tighten ownership checks post CVE-2022-24765
  git-compat-util: allow root to access both SUDO_UID and root owned
  t0034: add negative tests and allow git init to mostly work under sudo
  git-compat-util: avoid failing dir ownership checks if running privileged
  t: regression git needs safe.directory when using sudo

23 months agoGit 2.34.4 v2.34.4
Johannes Schindelin [Thu, 23 Jun 2022 10:35:49 +0000 (12:35 +0200)] 
Git 2.34.4

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23 months agoSync with 2.33.4
Johannes Schindelin [Thu, 23 Jun 2022 10:35:47 +0000 (12:35 +0200)] 
Sync with 2.33.4

* maint-2.33:
  Git 2.33.4
  Git 2.32.3
  Git 2.31.4
  Git 2.30.5
  setup: tighten ownership checks post CVE-2022-24765
  git-compat-util: allow root to access both SUDO_UID and root owned
  t0034: add negative tests and allow git init to mostly work under sudo
  git-compat-util: avoid failing dir ownership checks if running privileged
  t: regression git needs safe.directory when using sudo

23 months agoGit 2.33.4 v2.33.4
Johannes Schindelin [Thu, 23 Jun 2022 10:35:41 +0000 (12:35 +0200)] 
Git 2.33.4

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23 months agoSync with 2.32.3
Johannes Schindelin [Thu, 23 Jun 2022 10:35:38 +0000 (12:35 +0200)] 
Sync with 2.32.3

* maint-2.32:
  Git 2.32.3
  Git 2.31.4
  Git 2.30.5
  setup: tighten ownership checks post CVE-2022-24765
  git-compat-util: allow root to access both SUDO_UID and root owned
  t0034: add negative tests and allow git init to mostly work under sudo
  git-compat-util: avoid failing dir ownership checks if running privileged
  t: regression git needs safe.directory when using sudo

23 months agoGit 2.32.3 v2.32.3
Johannes Schindelin [Thu, 23 Jun 2022 10:35:32 +0000 (12:35 +0200)] 
Git 2.32.3

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23 months agoSync with 2.31.4
Johannes Schindelin [Thu, 23 Jun 2022 10:35:30 +0000 (12:35 +0200)] 
Sync with 2.31.4

* maint-2.31:
  Git 2.31.4
  Git 2.30.5
  setup: tighten ownership checks post CVE-2022-24765
  git-compat-util: allow root to access both SUDO_UID and root owned
  t0034: add negative tests and allow git init to mostly work under sudo
  git-compat-util: avoid failing dir ownership checks if running privileged
  t: regression git needs safe.directory when using sudo

23 months agoGit 2.31.4 v2.31.4
Johannes Schindelin [Thu, 23 Jun 2022 10:35:25 +0000 (12:35 +0200)] 
Git 2.31.4

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23 months agoSync with 2.30.5
Johannes Schindelin [Thu, 23 Jun 2022 10:35:23 +0000 (12:35 +0200)] 
Sync with 2.30.5

* maint-2.30:
  Git 2.30.5
  setup: tighten ownership checks post CVE-2022-24765
  git-compat-util: allow root to access both SUDO_UID and root owned
  t0034: add negative tests and allow git init to mostly work under sudo
  git-compat-util: avoid failing dir ownership checks if running privileged
  t: regression git needs safe.directory when using sudo

23 months agoGit 2.30.5 v2.30.5
Johannes Schindelin [Fri, 27 May 2022 21:38:36 +0000 (23:38 +0200)] 
Git 2.30.5

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23 months agosetup: tighten ownership checks post CVE-2022-24765
Carlo Marcelo Arenas Belón [Tue, 10 May 2022 19:35:29 +0000 (12:35 -0700)] 
setup: tighten ownership checks post CVE-2022-24765

8959555cee7 (setup_git_directory(): add an owner check for the top-level
directory, 2022-03-02), adds a function to check for ownership of
repositories using a directory that is representative of it, and ways to
add exempt a specific repository from said check if needed, but that
check didn't account for owership of the gitdir, or (when used) the
gitfile that points to that gitdir.

An attacker could create a git repository in a directory that they can
write into but that is owned by the victim to work around the fix that
was introduced with CVE-2022-24765 to potentially run code as the
victim.

An example that could result in privilege escalation to root in *NIX would
be to set a repository in a shared tmp directory by doing (for example):

  $ git -C /tmp init

To avoid that, extend the ensure_valid_ownership function to be able to
check for all three paths.

This will have the side effect of tripling the number of stat() calls
when a repository is detected, but the effect is expected to be likely
minimal, as it is done only once during the directory walk in which Git
looks for a repository.

Additionally make sure to resolve the gitfile (if one was used) to find
the relevant gitdir for checking.

While at it change the message printed on failure so it is clear we are
referring to the repository by its worktree (or gitdir if it is bare) and
not to a specific directory.

Helped-by: Junio C Hamano <junio@pobox.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
23 months agoMerge branch 'cb/path-owner-check-with-sudo'
Junio C Hamano [Thu, 26 May 2022 21:51:32 +0000 (14:51 -0700)] 
Merge branch 'cb/path-owner-check-with-sudo'

With a recent update to refuse access to repositories of other
people by default, "sudo make install" and "sudo git describe"
stopped working.  This series intends to loosen it while keeping
the safety.

* cb/path-owner-check-with-sudo:
  t0034: add negative tests and allow git init to mostly work under sudo
  git-compat-util: avoid failing dir ownership checks if running privileged
  t: regression git needs safe.directory when using sudo

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23 months agogit-compat-util: allow root to access both SUDO_UID and root owned
Carlo Marcelo Arenas Belón [Fri, 17 Jun 2022 20:23:38 +0000 (13:23 -0700)] 
git-compat-util: allow root to access both SUDO_UID and root owned

Previous changes introduced a regression which will prevent root for
accessing repositories owned by thyself if using sudo because SUDO_UID
takes precedence.

Loosen that restriction by allowing root to access repositories owned
by both uid by default and without having to add a safe.directory
exception.

A previous workaround that was documented in the tests is no longer
needed so it has been removed together with its specially crafted
prerequisite.

Helped-by: Johanness Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot0034: add negative tests and allow git init to mostly work under sudo
Carlo Marcelo Arenas Belón [Fri, 13 May 2022 01:00:19 +0000 (18:00 -0700)] 
t0034: add negative tests and allow git init to mostly work under sudo

Add a support library that provides one function that can be used
to run a "scriplet" of commands through sudo and that helps invoking
sudo in the slightly awkward way that is required to ensure it doesn't
block the call (if shell was allowed as tested in the prerequisite)
and it doesn't run the command through a different shell than the one
we intended.

Add additional negative tests as suggested by Junio and that use a
new workspace that is owned by root.

Document a regression that was introduced by previous commits where
root won't be able anymore to access directories they own unless
SUDO_UID is removed from their environment.

The tests document additional ways that this new restriction could
be worked around and the documentation explains why it might be instead
considered a feature, but a "fix" is planned for a future change.

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agogit-compat-util: avoid failing dir ownership checks if running privileged
Carlo Marcelo Arenas Belón [Fri, 13 May 2022 01:00:18 +0000 (18:00 -0700)] 
git-compat-util: avoid failing dir ownership checks if running privileged

bdc77d1d685 (Add a function to determine whether a path is owned by the
current user, 2022-03-02) checks for the effective uid of the running
process using geteuid() but didn't account for cases where that user was
root (because git was invoked through sudo or a compatible tool) and the
original uid that repository trusted for its config was no longer known,
therefore failing the following otherwise safe call:

  guy@renard ~/Software/uncrustify $ sudo git describe --always --dirty
  [sudo] password for guy:
  fatal: unsafe repository ('/home/guy/Software/uncrustify' is owned by someone else)

Attempt to detect those cases by using the environment variables that
those tools create to keep track of the original user id, and do the
ownership check using that instead.

This assumes the environment the user is running on after going
privileged can't be tampered with, and also adds code to restrict that
the new behavior only applies if running as root, therefore keeping the
most common case, which runs unprivileged, from changing, but because of
that, it will miss cases where sudo (or an equivalent) was used to change
to another unprivileged user or where the equivalent tool used to raise
privileges didn't track the original id in a sudo compatible way.

Because of compatibility with sudo, the code assumes that uid_t is an
unsigned integer type (which is not required by the standard) but is used
that way in their codebase to generate SUDO_UID.  In systems where uid_t
is signed, sudo might be also patched to NOT be unsigned and that might
be able to trigger an edge case and a bug (as described in the code), but
it is considered unlikely to happen and even if it does, the code would
just mostly fail safely, so there was no attempt either to detect it or
prevent it by the code, which is something that might change in the future,
based on expected user feedback.

Reported-by: Guy Maurel <guy.j@maurel.de>
Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Randall Becker <rsbecker@nexbridge.com>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot: regression git needs safe.directory when using sudo
Carlo Marcelo Arenas Belón [Fri, 13 May 2022 01:00:17 +0000 (18:00 -0700)] 
t: regression git needs safe.directory when using sudo

Originally reported after release of v2.35.2 (and other maint branches)
for CVE-2022-24765 and blocking otherwise harmless commands that were
done using sudo in a repository that was owned by the user.

Add a new test script with very basic support to allow running git
commands through sudo, so a reproduction could be implemented and that
uses only `git status` as a proxy of the issue reported.

Note that because of the way sudo interacts with the system, a much
more complete integration with the test framework will require a lot
more work and that was therefore intentionally punted for now.

The current implementation requires the execution of a special cleanup
function which should always be kept as the last "test" or otherwise
the standard cleanup functions will fail because they can't remove
the root owned directories that are used.  This also means that if
failures are found while running, the specifics of the failure might
not be kept for further debugging and if the test was interrupted, it
will be necessary to clean the working directory manually before
restarting by running:

  $ sudo rm -rf trash\ directory.t0034-root-safe-directory/

The test file also uses at least one initial "setup" test that creates
a parallel execution directory under the "root" sub directory, which
should be used as top level directory for all repositories that are
used in this test file.  Unlike all other tests the repository provided
by the test framework should go unused.

Special care should be taken when invoking commands through sudo, since
the environment is otherwise independent from what the test framework
setup and might have changed the values for HOME, SHELL and dropped
several relevant environment variables for your test.  Indeed `git status`
was used as a proxy because it doesn't even require commits in the
repository to work and usually doesn't require much from the environment
to run, but a future patch will add calls to `git init` and that will
fail to honor the default branch name, unless that setting is NOT
provided through an environment variable (which means even a CI run
could fail that test if enabled incorrectly).

A new SUDO prerequisite is provided that does some sanity checking
to make sure the sudo command that will be used allows for passwordless
execution as root without restrictions and doesn't mess with git's
execution path.  This matches what is provided by the macOS agents that
are used as part of GitHub actions and probably nowhere else.

Most of those characteristics make this test mostly only suitable for
CI, but it might be executed locally if special care is taken to provide
for all of them in the local configuration and maybe making use of the
sudo credential cache by first invoking sudo, entering your password if
needed, and then invoking the test with:

  $ GIT_TEST_ALLOW_SUDO=YES ./t0034-root-safe-directory.sh

If it fails to run, then it means your local setup wouldn't work for the
test because of the configuration sudo has or other system settings, and
things that might help are to comment out sudo's secure_path config, and
make sure that the account you are using has no restrictions on the
commands it can run through sudo, just like is provided for the user in
the CI.

For example (assuming a username of marta for you) something probably
similar to the following entry in your /etc/sudoers (or equivalent) file:

  marta ALL=(ALL:ALL) NOPASSWD: ALL

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.35.3 v2.35.3
Junio C Hamano [Wed, 13 Apr 2022 22:21:34 +0000 (15:21 -0700)] 
Git 2.35.3

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.34.3 v2.34.3
Junio C Hamano [Wed, 13 Apr 2022 22:21:31 +0000 (15:21 -0700)] 
Git 2.34.3

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.33.3 v2.33.3
Junio C Hamano [Wed, 13 Apr 2022 22:21:28 +0000 (15:21 -0700)] 
Git 2.33.3

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.32.2 v2.32.2
Junio C Hamano [Wed, 13 Apr 2022 22:21:26 +0000 (15:21 -0700)] 
Git 2.32.2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.31.3 v2.31.3
Junio C Hamano [Wed, 13 Apr 2022 22:21:08 +0000 (15:21 -0700)] 
Git 2.31.3

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.30.4 v2.30.4
Junio C Hamano [Wed, 13 Apr 2022 20:31:29 +0000 (13:31 -0700)] 
Git 2.30.4

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agosetup: opt-out of check with safe.directory=*
Derrick Stolee [Wed, 13 Apr 2022 15:32:31 +0000 (15:32 +0000)] 
setup: opt-out of check with safe.directory=*

With the addition of the safe.directory in 8959555ce
(setup_git_directory(): add an owner check for the top-level directory,
2022-03-02) released in v2.35.2, we are receiving feedback from a
variety of users about the feature.

Some users have a very large list of shared repositories and find it
cumbersome to add this config for every one of them.

In a more difficult case, certain workflows involve running Git commands
within containers. The container boundary prevents any global or system
config from communicating `safe.directory` values from the host into the
container. Further, the container almost always runs as a different user
than the owner of the directory in the host.

To simplify the reactions necessary for these users, extend the
definition of the safe.directory config value to include a possible '*'
value. This value implies that all directories are safe, providing a
single setting to opt-out of this protection.

Note that an empty assignment of safe.directory clears all previous
values, and this is already the case with the "if (!value || !*value)"
condition.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agosetup: fix safe.directory key not being checked
Matheus Valadares [Wed, 13 Apr 2022 15:32:30 +0000 (15:32 +0000)] 
setup: fix safe.directory key not being checked

It seems that nothing is ever checking to make sure the safe directories
in the configs actually have the key safe.directory, so some unrelated
config that has a value with a certain directory would also make it a
safe directory.

Signed-off-by: Matheus Valadares <me@m28.io>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot0033: add tests for safe.directory
Derrick Stolee [Wed, 13 Apr 2022 15:32:29 +0000 (15:32 +0000)] 
t0033: add tests for safe.directory

It is difficult to change the ownership on a directory in our test
suite, so insert a new GIT_TEST_ASSUME_DIFFERENT_OWNER environment
variable to trick Git into thinking we are in a differently-owned
directory. This allows us to test that the config is parsed correctly.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.35.2 v2.35.2
Johannes Schindelin [Thu, 17 Mar 2022 09:58:00 +0000 (10:58 +0100)] 
Git 2.35.2

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoSync with 2.34.2
Johannes Schindelin [Thu, 17 Mar 2022 09:57:59 +0000 (10:57 +0100)] 
Sync with 2.34.2

* maint-2.34:
  Git 2.34.2
  Git 2.33.2
  Git 2.32.1
  Git 2.31.2
  GIT-VERSION-GEN: bump to v2.33.1
  Git 2.30.3
  setup_git_directory(): add an owner check for the top-level directory
  Add a function to determine whether a path is owned by the current user

2 years agoGit 2.34.2 v2.34.2
Johannes Schindelin [Thu, 17 Mar 2022 09:57:52 +0000 (10:57 +0100)] 
Git 2.34.2

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoSync with 2.33.2
Johannes Schindelin [Thu, 17 Mar 2022 09:57:50 +0000 (10:57 +0100)] 
Sync with 2.33.2

* maint-2.33:
  Git 2.33.2
  Git 2.32.1
  Git 2.31.2
  GIT-VERSION-GEN: bump to v2.33.1
  Git 2.30.3
  setup_git_directory(): add an owner check for the top-level directory
  Add a function to determine whether a path is owned by the current user

2 years agoGit 2.33.2 v2.33.2
Johannes Schindelin [Thu, 17 Mar 2022 09:57:44 +0000 (10:57 +0100)] 
Git 2.33.2

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoSync with 2.32.1
Johannes Schindelin [Thu, 17 Mar 2022 09:57:43 +0000 (10:57 +0100)] 
Sync with 2.32.1

* maint-2.32:
  Git 2.32.1
  Git 2.31.2
  Git 2.30.3
  setup_git_directory(): add an owner check for the top-level directory
  Add a function to determine whether a path is owned by the current user

2 years agoGit 2.32.1 v2.32.1
Johannes Schindelin [Thu, 17 Mar 2022 09:57:38 +0000 (10:57 +0100)] 
Git 2.32.1

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoSync with 2.31.2
Johannes Schindelin [Thu, 17 Mar 2022 09:57:37 +0000 (10:57 +0100)] 
Sync with 2.31.2

* maint-2.31:
  Git 2.31.2
  Git 2.30.3
  setup_git_directory(): add an owner check for the top-level directory
  Add a function to determine whether a path is owned by the current user

2 years agoGit 2.31.2 v2.31.2
Johannes Schindelin [Thu, 17 Mar 2022 09:57:32 +0000 (10:57 +0100)] 
Git 2.31.2

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoSync with 2.30.3
Johannes Schindelin [Thu, 17 Mar 2022 09:57:31 +0000 (10:57 +0100)] 
Sync with 2.30.3

* maint-2.30:
  Git 2.30.3
  setup_git_directory(): add an owner check for the top-level directory
  Add a function to determine whether a path is owned by the current user

2 years agoGit 2.30.3 v2.30.3
Johannes Schindelin [Thu, 17 Mar 2022 09:15:15 +0000 (10:15 +0100)] 
Git 2.30.3

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoFix `GIT_CEILING_DIRECTORIES` with `C:\` and the likes
Johannes Schindelin [Wed, 23 Mar 2022 22:00:41 +0000 (23:00 +0100)] 
Fix `GIT_CEILING_DIRECTORIES` with `C:\` and the likes

When determining the length of the longest ancestor of a given path with
respect to to e.g. `GIT_CEILING_DIRECTORIES`, we special-case the root
directory by returning 0 (i.e. we pretend that the path `/` does not end
in a slash by virtually stripping it).

That is the correct behavior because when normalizing paths, the root
directory is special: all other directory paths have their trailing
slash stripped, but not the root directory's path (because it would
become the empty string, which is not a legal path).

However, this special-casing of the root directory in
`longest_ancestor_length()` completely forgets about Windows-style root
directories, e.g. `C:\`. These _also_ get normalized with a trailing
slash (because `C:` would actually refer to the current directory on
that drive, not necessarily to its root directory).

In fc56c7b34b (mingw: accomodate t0060-path-utils for MSYS2,
2016-01-27), we almost got it right. We noticed that
`longest_ancestor_length()` expects a slash _after_ the matched prefix,
and if the prefix already ends in a slash, the normalized path won't
ever match and -1 is returned.

But then that commit went astray: The correct fix is not to adjust the
_tests_ to expect an incorrect -1 when that function is fed a prefix
that ends in a slash, but instead to treat such a prefix as if the
trailing slash had been removed.

Likewise, that function needs to handle the case where it is fed a path
that ends in a slash (not only a prefix that ends in a slash): if it
matches the prefix (plus trailing slash), we still need to verify that
the path does not end there, otherwise the prefix is not actually an
ancestor of the path but identical to it (and we need to return -1 in
that case).

With these two adjustments, we no longer need to play games in t0060
where we only add `$rootoff` if the passed prefix is different from the
MSYS2 pseudo root, instead we also add it for the MSYS2 pseudo root
itself. We do have to be careful to skip that logic entirely for Windows
paths, though, because they do are not subject to that MSYS2 pseudo root
treatment.

This patch fixes the scenario where a user has set
`GIT_CEILING_DIRECTORIES=C:\`, which would be ignored otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agosetup_git_directory(): add an owner check for the top-level directory
Johannes Schindelin [Wed, 2 Mar 2022 11:23:04 +0000 (12:23 +0100)] 
setup_git_directory(): add an owner check for the top-level directory

It poses a security risk to search for a git directory outside of the
directories owned by the current user.

For example, it is common e.g. in computer pools of educational
institutes to have a "scratch" space: a mounted disk with plenty of
space that is regularly swiped where any authenticated user can create
a directory to do their work. Merely navigating to such a space with a
Git-enabled `PS1` when there is a maliciously-crafted `/scratch/.git/`
can lead to a compromised account.

The same holds true in multi-user setups running Windows, as `C:\` is
writable to every authenticated user by default.

To plug this vulnerability, we stop Git from accepting top-level
directories owned by someone other than the current user. We avoid
looking at the ownership of each and every directories between the
current and the top-level one (if there are any between) to avoid
introducing a performance bottleneck.

This new default behavior is obviously incompatible with the concept of
shared repositories, where we expect the top-level directory to be owned
by only one of its legitimate users. To re-enable that use case, we add
support for adding exceptions from the new default behavior via the
config setting `safe.directory`.

The `safe.directory` config setting is only respected in the system and
global configs, not from repository configs or via the command-line, and
can have multiple values to allow for multiple shared repositories.

We are particularly careful to provide a helpful message to any user
trying to use a shared repository.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoAdd a function to determine whether a path is owned by the current user
Johannes Schindelin [Wed, 2 Mar 2022 10:06:24 +0000 (11:06 +0100)] 
Add a function to determine whether a path is owned by the current user

This function will be used in the next commit to prevent
`setup_git_directory()` from discovering a repository in a directory
that is owned by someone other than the current user.

Note: We cannot simply use `st.st_uid` on Windows just like we do on
Linux and other Unix-like platforms: according to
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions
this field is always zero on Windows (because Windows' idea of a user ID
does not fit into a single numerical value). Therefore, we have to do
something a little involved to replicate the same functionality there.

Also note: On Windows, a user's home directory is not actually owned by
said user, but by the administrator. For all practical purposes, it is
under the user's control, though, therefore we pretend that it is owned
by the user.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoMerge branch 'cb/mingw-gmtime-r'
Johannes Schindelin [Thu, 17 Mar 2022 11:52:12 +0000 (12:52 +0100)] 
Merge branch 'cb/mingw-gmtime-r'

Build fix on Windows.

* cb/mingw-gmtime-r:
  mingw: avoid fallback for {local,gm}time_r()

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agomingw: avoid fallback for {local,gm}time_r()
Carlo Marcelo Arenas Belón [Sat, 27 Nov 2021 10:15:32 +0000 (10:15 +0000)] 
mingw: avoid fallback for {local,gm}time_r()

mingw-w64's pthread_unistd.h had a bug that mistakenly (because there is
no support for the *lockfile() functions required[1]) defined
_POSIX_THREAD_SAFE_FUNCTIONS and that was being worked around since
3ecd153a3b (compat/mingw: support MSys2-based MinGW build, 2016-01-14).

The bug was fixed in winphtreads, but as a side effect, leaves the
reentrant functions from time.h no longer visible and therefore breaks
the build.

Since the intention all along was to avoid using the fallback functions,
formalize the use of POSIX by setting the corresponding feature flag and
compile out the implementation for the fallback functions.

[1] https://unix.org/whitepapers/reentrant.html

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGIT-VERSION-GEN: bump to v2.33.1
Johannes Schindelin [Thu, 17 Mar 2022 09:35:52 +0000 (10:35 +0100)] 
GIT-VERSION-GEN: bump to v2.33.1

This was missed in af6d1d602a8f (Git 2.33.1, 2021-10-12).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 years agoGit 2.35.1 v2.35.1
Junio C Hamano [Sat, 29 Jan 2022 00:48:42 +0000 (16:48 -0800)] 
Git 2.35.1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'en/keep-cwd' into maint
Junio C Hamano [Sat, 29 Jan 2022 00:45:39 +0000 (16:45 -0800)] 
Merge branch 'en/keep-cwd' into maint

Fix a regression in 2.35 that roke the use of "rebase" and "stash"
in a secondary worktree.

* en/keep-cwd:
  sequencer, stash: fix running from worktree subdir

2 years agosequencer, stash: fix running from worktree subdir
Elijah Newren [Wed, 26 Jan 2022 01:43:45 +0000 (01:43 +0000)] 
sequencer, stash: fix running from worktree subdir

In commits bc3ae46b42 ("rebase: do not attempt to remove
startup_info->original_cwd", 2021-12-09) and 0fce211ccc ("stash: do not
attempt to remove startup_info->original_cwd", 2021-12-09), we wanted to
allow the subprocess to know which directory the parent process was
running from, so that the subprocess could protect it.  However...

When run from a non-main worktree, setup_git_directory() will note
that the discovered git directory
(/PATH/TO/.git/worktree/non-main-worktree) does not match
DEFAULT_GIT_DIR_ENVIRONMENT (see setup_discovered_git_dir()), and
decide to set GIT_DIR in the environment.  This matters because...

Whenever git is run with the GIT_DIR environment variable set, and
GIT_WORK_TREE not set, it presumes that '.' is the working tree.  So...

This combination results in the subcommand being very confused about
the working tree.  Fix it by also setting the GIT_WORK_TREE environment
variable along with setting cmd.dir.

A possibly more involved fix we could consider for later would be to
make setup.c set GIT_WORK_TREE whenever (a) it discovers both the git
directory and the working tree and (b) it decides to set GIT_DIR in the
environment.  I did not attempt that here as such would be too big of a
change for a 2.35.1 release.

Test-case-by: Glen Choo <chooglen@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoGit 2.35 v2.35.0
Junio C Hamano [Mon, 24 Jan 2022 17:25:25 +0000 (09:25 -0800)] 
Git 2.35

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/checkout-branch-info-leakfix'
Junio C Hamano [Mon, 24 Jan 2022 17:14:46 +0000 (09:14 -0800)] 
Merge branch 'ab/checkout-branch-info-leakfix'

We added an unrelated sanity checking that leads to a BUG() while
plugging a leak, which triggered in a repository with symrefs in
the local branch namespace that point at a ref outside.  Partially
revert the change to avoid triggering the BUG().

* ab/checkout-branch-info-leakfix:
  checkout: avoid BUG() when hitting a broken repository

2 years agoMerge tag 'l10n-2.35.0-rnd2' of git://github.com/git-l10n/git-po
Junio C Hamano [Mon, 24 Jan 2022 17:09:34 +0000 (09:09 -0800)] 
Merge tag 'l10n-2.35.0-rnd2' of git://github.com/git-l10n/git-po

l10n-2.35.0-rnd2

* tag 'l10n-2.35.0-rnd2' of git://github.com/git-l10n/git-po:
  l10n: Update Catalan translation
  l10n: zh_TW: v2.35.0 round 2 (0 untranslated)
  l10n: Update Catalan translation
  l10n: de.po: Update German translation
  l10n: de.po: Fix translation for "'%s' is aliased to '%s'"
  l10n: po-id for 2.35 (round 2)
  l10n: Update Catalan translation
  l10n: vi(5195t): Update for v2.35.0 round 2
  l10n: batch update to fix typo in branch.c
  l10n: git.pot: v2.35.0 round 2 (1 new, 1 removed)
  l10n: bg.po: Updated Bulgarian translation (5195t)
  l10n: zh_CN: v2.35.0 round 1
  l10n: fr: v2.35.0 round 1
  l10n: zh_TW: v2.35.0 round 1 (1 fuzzy)
  l10n: po-id for 2.35 (round 1)
  l10n: sv.po: Update Swedish translation (5196t0f0u)
  l10n: sv.po: Fix typo
  l10n: tr: v2.35.0 round 1
  l10n: git.pot: v2.35.0 round 1 (126 new, 142 removed)

2 years agol10n: Update Catalan translation
Jordi Mas [Sun, 23 Jan 2022 08:40:52 +0000 (09:40 +0100)] 
l10n: Update Catalan translation

Signed-off-by: Jordi Mas <jmas@softcatala.org>
2 years agoMerge branch 'l10n/zh_TW/220113' of github.com:l10n-tw/git-po
Jiang Xin [Sat, 22 Jan 2022 08:27:41 +0000 (16:27 +0800)] 
Merge branch 'l10n/zh_TW/220113' of github.com:l10n-tw/git-po

* 'l10n/zh_TW/220113' of github.com:l10n-tw/git-po:
  l10n: zh_TW: v2.35.0 round 2 (0 untranslated)
  l10n: zh_TW: v2.35.0 round 1 (1 fuzzy)

2 years agocheckout: avoid BUG() when hitting a broken repository
Junio C Hamano [Sat, 22 Jan 2022 00:58:30 +0000 (16:58 -0800)] 
checkout: avoid BUG() when hitting a broken repository

When 9081a421 (checkout: fix "branch info" memory leaks, 2021-11-16)
cleaned up existing memory leaks, we added an unrelated sanity check
to ensure that a local branch is truly local and not a symref to
elsewhere that dies with BUG() otherwise.  This was misguided in two
ways.  First of all, such a tightening did not belong to a leak-fix
patch.  And the condition it detected was *not* a bug in our program
but a problem in user data, where warning() or die() would have been
more appropriate.

As the condition is not fatal (the result of computing the local
branch name in the code that is involved in the faulty check is only
used as a textual label for the commit), let's revert the code to
the original state, i.e. strip "refs/heads/" to compute the local
branch name if possible, and otherwise leave it NULL.  The consumer
of the information in merge_working_tree() is prepared to see NULL
in there and act accordingly.

cf. https://bugzilla.redhat.com/show_bug.cgi?id=2042920

Reported-by: Petr Šplíchal <psplicha@redhat.com>
Reported-by: Todd Zullinger <tmz@pobox.com>
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agol10n: zh_TW: v2.35.0 round 2 (0 untranslated)
Yi-Jyun Pan [Fri, 21 Jan 2022 23:06:36 +0000 (07:06 +0800)] 
l10n: zh_TW: v2.35.0 round 2 (0 untranslated)

Used 1 translation from zh_CN. Thanks to zh_CN translation team!

Signed-off-by: Yi-Jyun Pan <pan93412@gmail.com>
2 years agol10n: Update Catalan translation
Jordi Mas [Fri, 21 Jan 2022 06:56:02 +0000 (07:56 +0100)] 
l10n: Update Catalan translation

Signed-off-by: Jordi Mas <jmas@softcatala.org>
2 years agoMerge branch 'js/branch-track-inherit'
Junio C Hamano [Thu, 20 Jan 2022 23:25:38 +0000 (15:25 -0800)] 
Merge branch 'js/branch-track-inherit'

"git branch -h" incorrectly said "--track[=direct|inherit]",
implying that "--trackinherit" is a valid option, which has been
corrected.
source: <3de40324bea6a1dd9bca2654721471e3809e87d8.1642538935.git.steadmon@google.com>
source: <c3c26192-aee9-185a-e559-b8735139e49c@web.de>

* js/branch-track-inherit:
  branch,checkout: fix --track documentation

2 years agobranch,checkout: fix --track documentation
René Scharfe [Thu, 20 Jan 2022 12:35:54 +0000 (13:35 +0100)] 
branch,checkout: fix --track documentation

Document that the accepted variants of the --track option are --track,
--track=direct, and --track=inherit.  The equal sign in the latter two
cannot be replaced with whitespace; in general optional arguments need
to be attached firmly to their option.

Put "direct" consistently before "inherit", if only for the reasons
that the former is the default, explained first in the documentation,
and comes before the latter alphabetically.

Mention both modes in the short help so that readers don't have to look
them up in the full documentation.  They are literal strings and thus
untranslatable.  PARSE_OPT_LITERAL_ARGHELP is inferred due to the pipe
and parenthesis characters, so we don't have to provide that flag
explicitly.

Mention that -t has the same effect as --track and --track=direct.
There is no way to specify inherit mode using the short option, because
short options generally don't accept optional arguments.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agol10n: de.po: Update German translation
Matthias Rüster [Sat, 15 Jan 2022 15:36:51 +0000 (16:36 +0100)] 
l10n: de.po: Update German translation

Signed-off-by: Matthias Rüster <matthias.ruester@gmail.com>
Reviewed-by: Ralf Thielow <ralf.thielow@gmail.com>
2 years agol10n: de.po: Fix translation for "'%s' is aliased to '%s'"
Jürgen Krämer [Thu, 18 Nov 2021 15:25:48 +0000 (16:25 +0100)] 
l10n: de.po: Fix translation for "'%s' is aliased to '%s'"

The German translation for "'%s' is aliased to '%s'" is incorrect. It
switches the order of alias name and alias definition.

A better translation would be "'%s' ist ein Alias für '%s'". (Full stop
removed intentionally, because the original does not use one either.)

Signed-off-by: Matthias Rüster <matthias.ruester@gmail.com>
2 years agoMerge branch 'po-id' of github.com:bagasme/git-po
Jiang Xin [Thu, 20 Jan 2022 02:40:08 +0000 (10:40 +0800)] 
Merge branch 'po-id' of github.com:bagasme/git-po

* 'po-id' of github.com:bagasme/git-po:
  l10n: po-id for 2.35 (round 2)

2 years agoGit 2.35-rc2 v2.35.0-rc2
Junio C Hamano [Wed, 19 Jan 2022 20:48:46 +0000 (12:48 -0800)] 
Git 2.35-rc2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agogetcwd(mingw): handle the case when there is no cwd
Johannes Schindelin [Wed, 19 Jan 2022 18:56:01 +0000 (18:56 +0000)] 
getcwd(mingw): handle the case when there is no cwd

A recent upstream topic introduced checks for certain Git commands that
prevent them from deleting the current working directory, introducing
also a regression test that ensures that commands such as `git version`
_can_ run without a current working directory.

While technically not possible on Windows via the regular Win32 API, we
do run the regression tests in an MSYS2 Bash which uses a POSIX
emulation layer (the MSYS2/Cygwin runtime) where a really evil hack
_does_ allow to delete a directory even if it is the current working
directory.

Therefore, Git needs to be prepared for a missing working directory,
even on Windows.

This issue was not noticed in upstream Git because there was no caller
that tried to discover a Git directory with a deleted current working
directory in the test suite. But in the microsoft/git fork, we do want
to run `pre-command`/`post-command` hooks for every command, even for
`git version`, which means that we make precisely such a call. The bug
is not in that `pre-command`/`post-command` feature, though, but in
`mingw_getcwd()` and needs to be addressed there.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agol10n: po-id for 2.35 (round 2)
Bagas Sanjaya [Tue, 18 Jan 2022 08:27:07 +0000 (15:27 +0700)] 
l10n: po-id for 2.35 (round 2)

Translate following new components:

  * advice.c
  * alias.c
  * sequencer.c
  * sparse-index.c
  * builtin/sparse-checkout.c

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
2 years agol10n: Update Catalan translation
Jordi Mas [Wed, 19 Jan 2022 06:50:14 +0000 (07:50 +0100)] 
l10n: Update Catalan translation

Signed-off-by: Jordi Mas <jmas@softcatala.org>
2 years agoMerge branch 'js/branch-track-inherit'
Junio C Hamano [Wed, 19 Jan 2022 00:02:23 +0000 (16:02 -0800)] 
Merge branch 'js/branch-track-inherit'

"git branch -h" incorrectly said "--track[=direct|inherit]",
implying that "--trackinherit" is a valid option, which has been
corrected.

* js/branch-track-inherit:
  branch,checkout: fix --track usage strings

2 years agoMerge branch 'jc/freebsd-without-c99-only-build'
Junio C Hamano [Wed, 19 Jan 2022 00:02:23 +0000 (16:02 -0800)] 
Merge branch 'jc/freebsd-without-c99-only-build'

FreeBSD 13.0 headers have unconditional dependency on C11 language
features, and adding -std=gnu99 to DEVELOPER_CFLAGS would just
break the developer build.

* jc/freebsd-without-c99-only-build:
  Makefile: FreeBSD cannot do C99-or-below build

2 years agobranch,checkout: fix --track usage strings
Josh Steadmon [Tue, 18 Jan 2022 20:49:46 +0000 (12:49 -0800)] 
branch,checkout: fix --track usage strings

As Ævar pointed out in [1], the use of PARSE_OPT_LITERAL_ARGHELP with a
list of allowed parameters is not recommended. Both git-branch and
git-checkout were changed in d311566 (branch: add flags and config to
inherit tracking, 2021-12-20) to use this discouraged combination for
their --track flags.

Fix this by removing PARSE_OPT_LITERAL_ARGHELP, and changing the arghelp
to simply be "mode". Users may discover allowed values in the manual
pages.

[1]: https://lore.kernel.org/git/220111.86a6g3yqf9.gmgdl@evledraar.gmail.com/

Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMakefile: FreeBSD cannot do C99-or-below build
Junio C Hamano [Tue, 18 Jan 2022 17:47:39 +0000 (09:47 -0800)] 
Makefile: FreeBSD cannot do C99-or-below build

In "make DEVELOPER=YesPlease" builds, we try to help developers to
catch as many potential issues as they can by using -Wall and
turning compilation warnings into errors.  In the same spirit, we
recently started adding -std=gnu99 to their CFLAGS, so that they can
notice when they accidentally used language features beyond C99.

It however turns out that FreeBSD 13.0 mistakenly uses C11 extension
in its system header files regardless of what __STDC_VERSION__ says,
which means that the platform (unless we tweak their system headers)
cannot be used for this purpose.

It seems that -std=gnu99 is only added conditionally even in today's
config.mak.dev, so it is fine if we dropped -std=gnu99 from there.
Which means that developers on FreeBSD cannot participate in vetting
use of features beyond C99, but there are developers on other
platforms who will, so it's not too bad.

We might want a more "fundamental" fix to make the platform capable
of taking -std=gnu99, like working around the use of unconditional
C11 extension in its system header files by supplying a set of
"replacement" definitions in our header files.  We chose not to
pursue such an approach for two reasons at this point:

 (1) The fix belongs to the FreeBSD project, not this project, and
     such an upstream fix may happen hopefully in a not-too-distant
     future.

 (2) Fixing such a bug in system header files and working it around
     can lead to unexpected breakages (other parts of their system
     header files may not be expecting to see and do not work well
     with our "replacement" definitions).  This close to the final
     release of this cycle, we have no time for that.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'da/rhel7-lacks-uncompress2-and-c99'
Junio C Hamano [Mon, 17 Jan 2022 23:15:59 +0000 (15:15 -0800)] 
Merge branch 'da/rhel7-lacks-uncompress2-and-c99'

Adjust build on RHEL 7 to explicitly ask C99 support and use
the fallback implementation of uncompress2 we ship.

* da/rhel7-lacks-uncompress2-and-c99:
  build: centos/RHEL 7 ships with an older gcc and zlib

2 years agol10n: vi(5195t): Update for v2.35.0 round 2
Tran Ngoc Quan [Mon, 17 Jan 2022 07:15:31 +0000 (14:15 +0700)] 
l10n: vi(5195t): Update for v2.35.0 round 2

Signed-off-by: Tran Ngoc Quan <vnwildman@gmail.com>
2 years agol10n: batch update to fix typo in branch.c
Jiang Xin [Mon, 17 Jan 2022 00:50:41 +0000 (08:50 +0800)] 
l10n: batch update to fix typo in branch.c

In git 2.35 l10n round 1, a space between two words was missing in the
message from "branch.c", and it was fixed by commit 68d924e1de (branch:
missing space fix at line 313, 2022-01-11).

Do a batch update for teams (bg, fr, id, sv, tr and zh_CN) that have
already completed their works on l10n round 1.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
2 years agol10n: git.pot: v2.35.0 round 2 (1 new, 1 removed)
Jiang Xin [Mon, 17 Jan 2022 00:32:09 +0000 (08:32 +0800)] 
l10n: git.pot: v2.35.0 round 2 (1 new, 1 removed)

Generate po/git.pot from v2.35.0-rc1 for git v2.35.0 l10n round 2.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
2 years agoMerge tag 'v2.35.0-rc1'
Jiang Xin [Mon, 17 Jan 2022 00:30:45 +0000 (08:30 +0800)] 
Merge tag 'v2.35.0-rc1'

Git 2.35-rc1

* tag 'v2.35.0-rc1':
  Git 2.35-rc1
  reftable tests: avoid "int" overflow, use "uint64_t"
  reftable: avoid initializing structs from structs
  t1450-fsck: exec-bit is not needed to make loose object writable
  refs API: use "failure_errno", not "errno"
  Last minute fixes before -rc1
  build: NonStop ships with an older zlib
  packfile: fix off-by-one error in decoding logic
  t/gpg: simplify test for unknown key
  branch: missing space fix at line 313
  fmt-merge-msg: prevent use-after-free with signed tags
  cache.h: drop duplicate `ensure_full_index()` declaration
  lazyload: use correct calling conventions
  fetch: fix deadlock when cleaning up lockfiles in async signals