From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 11/11] shallow: fix NULL dereference
Date: Thu, 09 Jul 2026 09:42:38 +0000 [thread overview]
Message-ID: <9f3a23948475eaa382e9507543fe08d933a4a461.1783590159.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2174.git.1783590159.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
After `write_one_shallow()` calls `lookup_commit()` to find the commit
object for a shallow graft entry, it then checks `if (!c || ...)`.
Inside that block, when the VERBOSE flag is set, it prints the OID being
removed, via `c->object.oid`. But `c` can be NULL (the first condition
in the `||` check).
This happens when a shallow graft entry references a commit object that
is not in the object store (e.g., after a partial fetch or in a
corrupted repository). In that case, `lookup_commit()` returns NULL
because the object cannot be found, the SEEN_ONLY check correctly
decides to remove this entry from .git/shallow, but the verbose message
crashes before the removal can complete.
Use `graft->oid` instead of `c->object.oid` for the message. The graft
entry's OID is the same value (it was used as the lookup key) and is
always available regardless of whether the commit object exists.
Pointed out by Coverity.
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
shallow.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shallow.c b/shallow.c
index 07cae44ae5..3d2230351e 100644
--- a/shallow.c
+++ b/shallow.c
@@ -371,7 +371,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (!c || !(c->object.flags & SEEN)) {
if (data->flags & VERBOSE)
printf("Removing %s from .git/shallow\n",
- oid_to_hex(&c->object.oid));
+ oid_to_hex(&graft->oid));
return 0;
}
}
--
gitgitgadget
next prev parent reply other threads:[~2026-07-09 9:42 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 9:42 [PATCH 00/11] coverity: avoid dereferencing NULL Johannes Schindelin via GitGitGadget
2026-07-09 9:42 ` [PATCH 01/11] diffcore-break: guard against NULLed queue entries in merge loop Johannes Schindelin via GitGitGadget
2026-07-10 3:11 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 02/11] diff: handle NULL return from repo_get_commit_tree() Johannes Schindelin via GitGitGadget
2026-07-10 3:11 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 03/11] remote: guard `remote_tracking()` against NULL remote Johannes Schindelin via GitGitGadget
2026-07-10 3:21 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 04/11] reftable/stack: guard against NULL list_file in stack_destroy Johannes Schindelin via GitGitGadget
2026-07-10 3:21 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 05/11] mailsplit: move NULL check before first use of file handle Johannes Schindelin via GitGitGadget
2026-07-10 3:31 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 06/11] bisect: handle NULL commit in `bisect_successful()` Johannes Schindelin via GitGitGadget
2026-07-10 3:31 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 07/11] replay: die when --onto does not peel to a commit Johannes Schindelin via GitGitGadget
2026-07-09 9:42 ` [PATCH 08/11] revision: avoid dereferencing NULL in `add_parents_only()` Johannes Schindelin via GitGitGadget
2026-07-10 3:41 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 09/11] pack-bitmap: handle missing bitmap for base MIDX Johannes Schindelin via GitGitGadget
2026-07-10 3:41 ` Junio C Hamano
2026-07-09 9:42 ` [PATCH 10/11] bisect: ensure non-NULL `head` before using it Johannes Schindelin via GitGitGadget
2026-07-10 4:01 ` Junio C Hamano
2026-07-09 9:42 ` Johannes Schindelin via GitGitGadget [this message]
2026-07-09 20:10 ` [PATCH 11/11] shallow: fix NULL dereference Junio C Hamano
2026-07-10 11:39 ` [PATCH v2 00/12] coverity: avoid dereferencing NULL Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 01/12] diffcore-break: guard against NULLed queue entries in merge loop Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 02/12] diff: handle NULL return from repo_get_commit_tree() Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 03/12] remote: guard `remote_tracking()` against NULL remote Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 04/12] reftable/stack: guard against NULL list_file in stack_destroy Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 05/12] mailsplit: move NULL check before first use of file handle Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 06/12] bisect: handle NULL commit in `bisect_successful()` Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 07/12] replay: die when --onto does not peel to a commit Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 08/12] revision: avoid dereferencing NULL in `add_parents_only()` Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 09/12] pack-bitmap: handle missing bitmap for base MIDX Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 10/12] bisect: ensure non-NULL `head` before using it Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 11/12] shallow: fix NULL dereference Johannes Schindelin via GitGitGadget
2026-07-10 11:39 ` [PATCH v2 12/12] shallow: give write_one_shallow() its own hex buffer Johannes Schindelin via GitGitGadget
2026-07-10 15:46 ` [PATCH v2 00/12] coverity: avoid dereferencing NULL Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f3a23948475eaa382e9507543fe08d933a4a461.1783590159.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.