patch(1): Don't overrun line buffer in some cases

Patches like file.txt attached to PR 190195 with a final line formed
like ">(EOL)" could cause a copy past the end of the current line buffer. In the
case of PR 191641, this caused a duplicate line to be copied into the resulting
file.

Instead of running past the end, treat it as if it were a blank line.

PR:		191641
Reviewed by:	cem, emaste, pfg
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D12609
This commit is contained in:
Kyle Evans 2017-10-09 14:50:02 +00:00
parent 4363782bc3
commit 4835edfa0d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=324431

View file

@ -1135,7 +1135,12 @@ another_hunk(void)
if (*buf != '>')
fatal("> expected at line %ld of patch\n",
p_input_line);
p_line[i] = savestr(buf + 2);
/* Don't overrun if we don't have enough line */
if (len > 2)
p_line[i] = savestr(buf + 2);
else
p_line[i] = savestr("");
if (out_of_mem) {
p_end = i - 1;
return false;