Fix out-of-bounds access to lines in a patch

This bug can trigger with malformed patches.
* src/pch.c (pch_write_line): Avoid out-of-bounds access to
p_line[line][p_len[line] - 1] when p_len[line] is 0.
This commit is contained in:
Hanno Boeck 2016-08-10 00:06:41 +02:00 committed by Andreas Gruenbacher
parent 4c43a0b1cb
commit a0d7fe4589

View File

@ -2276,7 +2276,7 @@ pfetch (lin line)
bool
pch_write_line (lin line, FILE *file)
{
bool after_newline = p_line[line][p_len[line] - 1] == '\n';
bool after_newline = (p_len[line] > 0) && (p_line[line][p_len[line] - 1] == '\n');
if (! fwrite (p_line[line], sizeof (*p_line[line]), p_len[line], file))
write_fatal ();
return after_newline;