Skip to content

Commit 97a20ee

Browse files
jrngitster
authored andcommitted
fix "bundle --stdin" segfault
When passed an empty list, objects_array_remove_duplicates() corrupts it by changing the number of entries from 0 to 1. The problem lies in the condition of its main loop: for (ref = 0; ref < array->nr - 1; ref++) { The loop body manipulates the supplied object array. In the case of an empty array, it should not be doing anything at all. But array->nr is an unsigned quantity, so the code enters the loop, in particular increasing array->nr. Fix this by comparing (ref + 1 < array->nr) instead. This bug can be triggered by git bundle --stdin: $ echo HEAD | git bundle create some.bundle --stdin’ Segmentation fault (core dumped) The list of commits to bundle appears to be empty because of another bug: by the time the revision-walking machinery gets to look at it, standard input has already been consumed by rev-list, so this function gets an empty list of revisions. After this patch, git bundle --stdin still does not work; it just doesn’t segfault any more. Reported-by: Joey Hess <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f62e0a3 commit 97a20ee

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj
252252

253253
void object_array_remove_duplicates(struct object_array *array)
254254
{
255-
int ref, src, dst;
255+
unsigned int ref, src, dst;
256256
struct object_array_entry *objects = array->objects;
257257

258-
for (ref = 0; ref < array->nr - 1; ref++) {
258+
for (ref = 0; ref + 1 < array->nr; ref++) {
259259
for (src = ref + 1, dst = src;
260260
src < array->nr;
261261
src++) {

0 commit comments

Comments
 (0)