summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2018-01-18 21:53:07 +0000
committerkevans <kevans@FreeBSD.org>2018-01-18 21:53:07 +0000
commitcf061e9c775ef6885d6864aeb2c3fcb067c51002 (patch)
treef8720b3680073c10628e3f73c549d06da99097ba /usr.bin
parent74eac5ce4a8596f71ab65a2a416dca94cdb17fe7 (diff)
downloadFreeBSD-src-cf061e9c775ef6885d6864aeb2c3fcb067c51002.zip
FreeBSD-src-cf061e9c775ef6885d6864aeb2c3fcb067c51002.tar.gz
MFC r326084: patch(1): don't assume 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
Diffstat (limited to 'usr.bin')
-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 1bdbcfb..0780b30 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)
OpenPOWER on IntegriCloud