From fb37e38fbe99039a479520b4b596f4bfc04e2a88 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sat, 30 Aug 2025 17:01:27 -0500 Subject: [PATCH] Revert "patch: fix pch_context() for unified diffs with no leading context" This reverts commit f97b6a8f84b3ed209c2aea0958a7b889d0bf27ed, 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 --- usr.bin/patch/pch.c | 2 +- usr.bin/patch/tests/unified_patch_test.sh | 21 --------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 9bc4599026a..71f73125a8c 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1054,7 +1054,7 @@ hunk_done: p_end = fillnew; malformed(); } - if (ch != ' ' && context >= 0) { + if (ch != ' ' && context > 0) { if (context < p_context) p_context = context; context = -1000; diff --git a/usr.bin/patch/tests/unified_patch_test.sh b/usr.bin/patch/tests/unified_patch_test.sh index a4b46ef3422..a9133290877 100755 --- a/usr.bin/patch/tests/unified_patch_test.sh +++ b/usr.bin/patch/tests/unified_patch_test.sh @@ -25,26 +25,6 @@ # SUCH DAMAGE. # -atf_test_case badfuzz -badfuzz_head() -{ - atf_set "descr" "Test for patch(1) erroneously fuzzing away action lines" -} -badfuzz_body() -{ - # PR 250511 demonstrates a scenario where patch(1) will happily apply a - # patch into the wrong location if we have some lines that are still - # similar in the trailing context. In the following example, it would - # actually replace the underscore before the second series of B\nC\nO - # with "Z", when the patch should have been rejected instead. - printf "A\nB\nC\nO\n_\nB\nC\nO\n" > file.orig - printf "Z\nB\nC\nO\n_\nB\nC\nO\n" > file - printf "OK\nDIFF1\nDIFF2\n\n_\nB\nC\nO\n" > file.newer - - atf_check -s not-exit:0 -o save:file.patch diff -u3 file.orig file - atf_check -s not-exit:0 -o not-empty patch file.newer file.patch -} - atf_test_case basic basic_body() { @@ -198,7 +178,6 @@ EOF atf_init_test_cases() { - atf_add_test_case badfuzz atf_add_test_case basic atf_add_test_case limited_ctx atf_add_test_case file_creation