git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] commit-reach: avoid NULL dereference
@ 2023-02-11 11:15 Eric Wong
  2023-02-11 22:43 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2023-02-11 11:15 UTC (permalink / raw)
  To: git; +Cc: Derrick Stolee

The loop at the top of can_all_from_reach_with_flag() already
accounts for `from->objects[i].item' being NULL, so it follows
the cleanup loop should also account for a NULL `from_one'.

I managed to segfault here on one of my giant, many-remote repos
using `git fetch --negotiation-tip=...  --negotiation-only'
where the --negotiation-tip= argument was a glob which (inadvertently)
captured more refs than I wanted.  I have not reproduced this
in a standalone test case.

Signed-off-by: Eric Wong <e@80x24.org>
---
 Not sure if somebody who understands the code better can come
 up with a good standalone test case.  I figure using the top
 loop as reference is sufficient evidence that this fix is needed.

 commit-reach.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/commit-reach.c b/commit-reach.c
index 2e33c599a82..1d7056338b7 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -807,8 +807,12 @@ int can_all_from_reach_with_flag(struct object_array *from,
 	clear_commit_marks_many(nr_commits, list, RESULT | assign_flag);
 	free(list);
 
-	for (i = 0; i < from->nr; i++)
-		from->objects[i].item->flags &= ~assign_flag;
+	for (i = 0; i < from->nr; i++) {
+		struct object *from_one = from->objects[i].item;
+
+		if (from_one)
+			from_one->flags &= ~assign_flag;
+	}
 
 	return result;
 }

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

end of thread, other threads:[~2023-02-13 17:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-11 11:15 [PATCH] commit-reach: avoid NULL dereference Eric Wong
2023-02-11 22:43 ` Junio C Hamano
2023-02-13 13:58   ` Derrick Stolee
2023-02-13 17:29     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).