1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-02 19:56:10 +02:00

negotiator/skipping: avoid stack overflow

mark_common() in negotiator/skipping.c may overflow the stack due to
recursive function calls. Avoid this by instead recursing using a
heap-allocated data structure.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Tan 2022-10-25 16:29:34 -07:00 committed by Junio C Hamano
parent 7d8dc5a1af
commit 4654134976

View File

@ -86,10 +86,14 @@ static int clear_marks(const char *refname, const struct object_id *oid,
/*
* Mark this SEEN commit and all its SEEN ancestors as COMMON.
*/
static void mark_common(struct data *data, struct commit *c)
static void mark_common(struct data *data, struct commit *seen_commit)
{
struct commit_list *p;
struct prio_queue queue = { NULL };
struct commit *c;
prio_queue_put(&queue, seen_commit);
while ((c = prio_queue_get(&queue))) {
struct commit_list *p;
if (c->object.flags & COMMON)
return;
c->object.flags |= COMMON;
@ -100,7 +104,8 @@ static void mark_common(struct data *data, struct commit *c)
return;
for (p = c->parents; p; p = p->next) {
if (p->item->object.flags & SEEN)
mark_common(data, p->item);
prio_queue_put(&queue, p->item);
}
}
}