Skip to content

Commit c5773dc

Browse files
Eric Wonggitster
authored andcommitted
commit-reach: avoid NULL dereference
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4067a64 commit c5773dc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

commit-reach.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,12 @@ int can_all_from_reach_with_flag(struct object_array *from,
628628
}
629629
free(list);
630630

631-
for (i = 0; i < from->nr; i++)
632-
from->objects[i].item->flags &= ~assign_flag;
631+
for (i = 0; i < from->nr; i++) {
632+
struct object *from_one = from->objects[i].item;
633+
634+
if (from_one)
635+
from_one->flags &= ~assign_flag;
636+
}
633637

634638
return result;
635639
}

0 commit comments

Comments
 (0)