Skip to content

Commit bd3941a

Browse files
committed
Merge branch 'en/rerere-multi-stage-1-fix'
A corner case bugfix in "git rerere" code. * en/rerere-multi-stage-1-fix: rerere: avoid buffer overrun t4200: demonstrate rerere segfault on specially crafted merge
2 parents e3d4ff0 + ad2bf0d commit bd3941a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

rerere.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ static int check_one_conflict(int i, int *type)
521521
}
522522

523523
*type = PUNTED;
524-
while (ce_stage(active_cache[i]) == 1)
524+
while (i < active_nr && ce_stage(active_cache[i]) == 1)
525525
i++;
526526

527527
/* Only handle regular files with both stages #2 and #3 */

t/t4200-rerere.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,4 +642,33 @@ test_expect_success 'rerere with inner conflict markers' '
642642
test_cmp expect actual
643643
'
644644

645+
test_expect_success 'setup simple stage 1 handling' '
646+
test_create_repo stage_1_handling &&
647+
(
648+
cd stage_1_handling &&
649+
650+
test_seq 1 10 >original &&
651+
git add original &&
652+
git commit -m original &&
653+
654+
git checkout -b A master &&
655+
git mv original A &&
656+
git commit -m "rename to A" &&
657+
658+
git checkout -b B master &&
659+
git mv original B &&
660+
git commit -m "rename to B"
661+
)
662+
'
663+
664+
test_expect_success 'test simple stage 1 handling' '
665+
(
666+
cd stage_1_handling &&
667+
668+
git config rerere.enabled true &&
669+
git checkout A^0 &&
670+
test_must_fail git merge B^0
671+
)
672+
'
673+
645674
test_done

0 commit comments

Comments
 (0)