remote: guard `remote_tracking()` against NULL remote
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>
Johannes Schindelin committed
Jul 10, 2026 at 11:39 UTC
2fdcce115a5ce4fe3d025858f958b92ab1c4d20e
1 file changed
+2
remote.c
+2
@@ -2713,6 +2713,8 @@ static int remote_tracking(struct remote *remote, const char *refname,
2713
{
2714
char *dst;
2715
2716
+ if (!remote)
2717
+ BUG("remote_tracking() called with NULL remote");
2718
dst = apply_refspecs(&remote->fetch, refname);
2719
if (!dst)
2720
return -1; /* no tracking ref for refname at remote */