summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanno Boeck <hanno@gentoo.org>2016-08-10 00:06:41 +0200
committerAndreas Gruenbacher <agruen@gnu.org>2016-08-10 00:13:25 +0200
commita0d7fe4589651c64bd16ddaaa634030bb0455866 (patch)
treead341e0eb9e86a6c315c3da806befd3637c3d938
parent4c43a0b1cbbba0ed58d79f3da9aca6d77124ad26 (diff)
downloadpatch-a0d7fe4589651c64bd16ddaaa634030bb0455866.tar.gz
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.
-rw-r--r--src/pch.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/pch.c b/src/pch.c
index 94a0ac1..3ba5394 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -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;