public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] path-walk: fix NULL pointer dereference in error message
@ 2026-03-20 11:45 Yuvraj Singh Chauhan
  2026-03-20 17:18 ` Tian Yuchen
  0 siblings, 1 reply; 5+ messages in thread
From: Yuvraj Singh Chauhan @ 2026-03-20 11:45 UTC (permalink / raw)
  To: git; +Cc: christian.couder, stolee, Yuvraj Singh Chauhan

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
---
 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;
 		}
 
-- 
2.53.0.582.gca1db8a0f7


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-21  4:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-03-21  4:05       ` Tian Yuchen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox