]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: guard `remote_tracking()` against NULL remote
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 10 Jul 2026 11:39:27 +0000 (11:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jul 2026 15:13:54 +0000 (08:13 -0700)
The `remote_tracking()` function unconditionally dereferences
`remote->fetch` without checking whether remote is NULL.

In practice, this never happens because the only caller (`apply_cas()`)
guards the calls to this function by checking the `use_tracking` and
`use_tracking_for_rest` attributes.

However, it requires quite involved reasoning to reach that conclusion,
and is therefore fragile. Just return -1 ("no tracking ref") when there
is no remote to work with.

Pointed out by Coverity.

Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c

index e6c52c850cac6308b1236f59782097e032c24fde..b17648d6ef32e4f438ff9426571d369421e84886 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -2713,6 +2713,8 @@ static int remote_tracking(struct remote *remote, const char *refname,
 {
        char *dst;
 
+       if (!remote)
+               BUG("remote_tracking() called with NULL remote");
        dst = apply_refspecs(&remote->fetch, refname);
        if (!dst)
                return -1; /* no tracking ref for refname at remote */