From: Tian Yuchen <a3205153416@gmail.com>
To: Yuvraj Singh Chauhan <ysinghcin@gmail.com>, git@vger.kernel.org
Cc: christian.couder@gmail.com, stolee@gmail.com
Subject: Re: [PATCH] path-walk: fix NULL pointer dereference in error message
Date: Sat, 21 Mar 2026 01:18:36 +0800 [thread overview]
Message-ID: <eca1a469-2e15-4466-ae58-978ffc23c177@gmail.com> (raw)
In-Reply-To: <20260320114556.3151040-1-ysinghcin@gmail.com>
Hello,
Thanks for the patch!
On 3/20/26 19:45, Yuvraj Singh Chauhan wrote:
> When lookup_tree() or lookup_blob() cannot find a tree entry's object,
> 'o' is set to NULL via:
>
> o = child ? &child->object : NULL;
>
> The subsequent null-check catches this correctly, but then dereferences
> 'o' to format the error message:
>
> error(_("failed to find object %s"), oid_to_hex(&o->oid));
>
> This causes a segfault instead of the intended diagnostic output.
> Fix this by using &entry.oid instead. 'entry' is the struct name_entry
> populated by tree_entry() on each loop iteration and holds the OID of
> the failing lookup
Checking for NULL and then dereference the pointer, a segfault is bound
to occur. I believe this is indeed a bug.
> ---
> path-walk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/path-walk.c b/path-walk.c
> index 364e4cfa19..839582380c 100644
> --- a/path-walk.c
> +++ b/path-walk.c
> @@ -171,7 +171,7 @@ static int add_tree_entries(struct path_walk_context *ctx,
>
> if (!o) {
> error(_("failed to find object %s"),
> - oid_to_hex(&o->oid));
> + oid_to_hex(&entry.oid));
> return -1;
> }
>
The change itself looks good to me.
However, I have a slight concern about the original code implementation:
> o = child ? &child->object : NULL;
This means that 'child = NULL' is the expected failure path. But why is
'NULL' returned? Does the object truly not exist, or was it simply not
parsed? Is 'failed to find object' sufficient to describe the cause of
the failure? I think that's debatable. (I’m not 'suggesting' that you
make this change; I just hope we can all think about it together ;)
Also, it looks like you forgot to include 'Signed-off-by' line when you
committed the changes. When you've gathered enough feedback to commit
v2, please remember to include it.
Regards,
Yuchen
next prev parent reply other threads:[~2026-03-20 17:18 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 [this message]
2026-03-20 17:32 ` Tian Yuchen
2026-03-20 17:47 ` Junio C Hamano
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=eca1a469-2e15-4466-ae58-978ffc23c177@gmail.com \
--to=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