diff options
author | Hanno Boeck <hanno@gentoo.org> | 2016-08-10 00:06:41 +0200 |
---|---|---|
committer | Andreas Gruenbacher <agruen@gnu.org> | 2016-08-10 00:13:25 +0200 |
commit | a0d7fe4589651c64bd16ddaaa634030bb0455866 (patch) | |
tree | ad341e0eb9e86a6c315c3da806befd3637c3d938 | |
parent | 4c43a0b1cbbba0ed58d79f3da9aca6d77124ad26 (diff) | |
download | patch-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.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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; |