Re: [PATCH] path-walk: fix NULL pointer dereference in error message
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 20, 2026, 17:47 UTC
- Message-ID
- <xmqqpl4ye6ll.fsf@gitster.g>
- In-Reply-To
- <9d0746d8-2194-4a13-812b-9b46d04c189a@gmail.com>
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;