diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index 24e09ed304ad..204b1146b94c 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 anymore 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)