Skip to content

Commit fb37e38

Browse files
committed
Revert "patch: fix pch_context() for unified diffs with no leading context"
This reverts commit f97b6a8, as it turns out our fuzz implementation is just too naive. We can have more leading context than trailing context and vice-versa, so we can't really assume they're the same. Restore the previous bug and we can work on it post-branch. Reported by: cy
1 parent ae7f8da commit fb37e38

File tree

2 files changed

+1
-22
lines changed

2 files changed

+1
-22
lines changed

usr.bin/patch/pch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ another_hunk(void)
10541054
p_end = fillnew;
10551055
malformed();
10561056
}
1057-
if (ch != ' ' && context >= 0) {
1057+
if (ch != ' ' && context > 0) {
10581058
if (context < p_context)
10591059
p_context = context;
10601060
context = -1000;

usr.bin/patch/tests/unified_patch_test.sh

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,6 @@
2525
# SUCH DAMAGE.
2626
#
2727

28-
atf_test_case badfuzz
29-
badfuzz_head()
30-
{
31-
atf_set "descr" "Test for patch(1) erroneously fuzzing away action lines"
32-
}
33-
badfuzz_body()
34-
{
35-
# PR 250511 demonstrates a scenario where patch(1) will happily apply a
36-
# patch into the wrong location if we have some lines that are still
37-
# similar in the trailing context. In the following example, it would
38-
# actually replace the underscore before the second series of B\nC\nO
39-
# with "Z", when the patch should have been rejected instead.
40-
printf "A\nB\nC\nO\n_\nB\nC\nO\n" > file.orig
41-
printf "Z\nB\nC\nO\n_\nB\nC\nO\n" > file
42-
printf "OK\nDIFF1\nDIFF2\n\n_\nB\nC\nO\n" > file.newer
43-
44-
atf_check -s not-exit:0 -o save:file.patch diff -u3 file.orig file
45-
atf_check -s not-exit:0 -o not-empty patch file.newer file.patch
46-
}
47-
4828
atf_test_case basic
4929
basic_body()
5030
{
@@ -198,7 +178,6 @@ EOF
198178

199179
atf_init_test_cases()
200180
{
201-
atf_add_test_case badfuzz
202181
atf_add_test_case basic
203182
atf_add_test_case limited_ctx
204183
atf_add_test_case file_creation

0 commit comments

Comments
 (0)