public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Tian Yuchen <a3205153416@gmail.com>
Cc: Yuvraj Singh Chauhan <ysinghcin@gmail.com>,
	 git@vger.kernel.org, christian.couder@gmail.com,
	 stolee@gmail.com
Subject: Re: [PATCH] path-walk: fix NULL pointer dereference in error message
Date: Fri, 20 Mar 2026 10:47:02 -0700	[thread overview]
Message-ID: <xmqqpl4ye6ll.fsf@gitster.g> (raw)
In-Reply-To: <9d0746d8-2194-4a13-812b-9b46d04c189a@gmail.com> (Tian Yuchen's message of "Sat, 21 Mar 2026 01:32:25 +0800")

Tian Yuchen <a3205153416@gmail.com> writes:

> Then the message 'failed to find object' is misleading when user 
> encounters the second scenario. Wouldn’t it be confusing if a user saw 
> this message, checked the object using 'git cat-file -t', and discovered 
> that the object actually exists?

For that, you'd need to remove the block in question and duplicate
the message generation, perhaps like so, to allow the message
properly localized.

But that is way outside the scope of the patch that was posted,
which was a surgical fix for a reference to an incorrect pointer, I
would have to say.

 path-walk.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git c/path-walk.c w/path-walk.c
index 364e4cfa19..bd2c47079e 100644
--- c/path-walk.c
+++ w/path-walk.c
@@ -161,20 +161,20 @@ static int add_tree_entries(struct path_walk_context *ctx,
 
 		if (type == OBJ_TREE) {
 			struct tree *child = lookup_tree(ctx->repo, &entry.oid);
-			o = child ? &child->object : NULL;
+			if (!child)
+				return error(_("failed to find tree object %s"),
+					     oid_to_hex(&entry.oid));
+			o = &child->object;
 		} else if (type == OBJ_BLOB) {
 			struct blob *child = lookup_blob(ctx->repo, &entry.oid);
-			o = child ? &child->object : NULL;
+			if (!child)
+				return error(_("failed to find blob object %s"),
+					     oid_to_hex(&entry.oid));
+			o = &child->object;
 		} else {
 			BUG("invalid type for tree entry: %d", type);
 		}
 
-		if (!o) {
-			error(_("failed to find object %s"),
-			      oid_to_hex(&o->oid));
-			return -1;
-		}
-
 		/* Skip this object if already seen. */
 		if (o->flags & SEEN)
 			continue;


  reply	other threads:[~2026-03-20 17:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 11:45 [PATCH] path-walk: fix NULL pointer dereference in error message Yuvraj Singh Chauhan
2026-03-20 17:18 ` Tian Yuchen
2026-03-20 17:32   ` Tian Yuchen
2026-03-20 17:47     ` Junio C Hamano [this message]
2026-03-21  4:05       ` Tian Yuchen

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=xmqqpl4ye6ll.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=a3205153416@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=stolee@gmail.com \
    --cc=ysinghcin@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox