aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2017-11-22 03:44:19 +0000
committerKyle Evans <kevans@FreeBSD.org>2017-11-22 03:44:19 +0000
commitbc4f0fe3588183058f52c53f9cf59b77e19842db (patch)
tree4bd459c0a1171ec7103e8ffebe9cf993aad6667d /usr.bin/patch
parentefa8edd5bb14e2b871741d061bbdbec2851f1624 (diff)
downloadsrc-bc4f0fe3588183058f52c53f9cf59b77e19842db.tar.gz
src-bc4f0fe3588183058f52c53f9cf59b77e19842db.zip
patch(1): don't assume a match if we run out of context to check
Patches with very little context (-U0 and -U1) could get misapplied if the file to be patched changes and a hunk is no longer applicable. Matching with fuzz would be attempted and default to a match when we unexpectedly ran out of context. This also affected patches with higher levels of context but had limited actual context due to the hunk being located near the beginning/end of file. PR: 74127, 223545 (exp-run) Reviewed by: emaste, pfg Approved by: emaste (mentor) Differential Revision: https://reviews.freebsd.org/D12631
Notes
Notes: svn path=/head/; revision=326084
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/patch.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 24e09ed304ad..822610671b43 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1026,6 +1026,9 @@ patch_match(LINENUM base, LINENUM offset, LINENUM fuzz)
const char *plineptr;
unsigned short plinelen;
+ /* Patch does not match if we don't have any more context to use */
+ if (pline > pat_lines)
+ return false;
for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) {
ilineptr = ifetch(iline, offset >= 0);
if (ilineptr == NULL)