Skip to content

Commit 167395b

Browse files
mroethkegitster
authored andcommitted
rerere: fix crashes due to unmatched opening conflict markers
When rerere handles a conflict with an unmatched opening conflict marker in a file with other conflicts, it will fail create a preimage and also fail allocate the status member of struct rerere_dir. Currently the status member is allocated after the error handling. This will lead to a SEGFAULT when the status member is accessed during cleanup of the failed parse. Additionally, in subsequent executions of rerere, after removing the MERGE_RR.lock manually, rerere crashes for a similar reason. MERGE_RR points to a conflict id that has no preimage, therefore the status member is not allocated and a SEGFAULT happens when trying to check if a preimage exists. Solve this by making sure the status field is allocated correctly and add tests to prevent the bug from reoccurring. This does not fix the root cause, failing to parse stray conflict markers, but I don't think we can do much better than recognizing it, printing an error, and moving on gracefully. Signed-off-by: Marcel Röthke <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9bbde12 commit 167395b

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

rerere.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ static void read_rr(struct repository *r, struct string_list *rr)
214214
buf.buf[hexsz] = '\0';
215215
id = new_rerere_id_hex(buf.buf);
216216
id->variant = variant;
217+
/*
218+
* make sure id->collection->status has enough space
219+
* for the variant we are interested in
220+
*/
221+
fit_variant(id->collection, variant);
217222
string_list_insert(rr, path)->util = id;
218223
}
219224
strbuf_release(&buf);

t/t4200-rerere.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,67 @@ test_expect_success 'test simple stage 1 handling' '
671671
)
672672
'
673673

674+
test_expect_success 'rerere does not crash with missing preimage' '
675+
git config rerere.enabled true &&
676+
677+
echo bar >test &&
678+
git add test &&
679+
git commit -m "one" &&
680+
git branch rerere_no_crash &&
681+
682+
echo foo >>test &&
683+
git add test &&
684+
git commit -m "two" &&
685+
686+
git checkout rerere_no_crash &&
687+
echo "bar" >>test &&
688+
git add test &&
689+
git commit -m "three" &&
690+
691+
test_must_fail git rebase main &&
692+
rm .git/rr-cache/*/preimage &&
693+
git rebase --abort
694+
'
695+
696+
test_expect_success 'rerere does not crash with unmatched conflict marker' '
697+
git config rerere.enabled true &&
698+
699+
echo bar >test &&
700+
git add test &&
701+
git commit -m "one" &&
702+
git branch rerere_no_preimage &&
703+
704+
cat >test <<-EOF &&
705+
test
706+
bar
707+
foobar
708+
EOF
709+
git add test &&
710+
git commit -m "two" &&
711+
712+
git checkout rerere_no_preimage &&
713+
echo "bar" >>test &&
714+
git add test &&
715+
git commit -m "three" &&
716+
717+
cat >test <<-EOF &&
718+
foobar
719+
bar
720+
bar
721+
EOF
722+
git add test &&
723+
git commit -m "four" &&
724+
725+
test_must_fail git rebase main &&
726+
cat >test <<-EOF &&
727+
test
728+
bar
729+
<<<<<<< HEAD
730+
foobar
731+
bar
732+
EOF
733+
git add test &&
734+
test_must_fail git rebase --continue
735+
'
736+
674737
test_done

0 commit comments

Comments
 (0)