From 5cc6db0c829353eef4591ac10a9a06c504e65134 Mon Sep 17 00:00:00 2001 From: Adrien Schildknecht Date: Wed, 10 Aug 2016 16:43:25 -0400 Subject: [PATCH] libext2fs: reset the size of the zeroing buffer When a ext2_filsys is freed, ext2fs_zero_blocks2() frees the buffer but does not reset its size. If this function is later called with a new ext2_filsys, the code assumes that the buffer is still valid and return a NULL pointer. Valgrind output: ==188948== Syscall param pwrite64(buf) points to unaddressable byte(s) ==188948== at 0x4E46D03: __pwrite_nocancel (syscall-template.S:81) ==188948== by 0x1254EC: raw_write_blk (unix_io.c:240) ==188948== by 0x124AAB: unix_write_blk64 (unix_io.c:850) ==188948== by 0x122893: ext2fs_zero_blocks2 (mkjournal.c:204) Signed-off-by: Adrien Schildknecht Signed-off-by: Theodore Ts'o --- lib/ext2fs/mkjournal.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index af983c72..43ffa53f 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -162,6 +162,7 @@ errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num, if (buf) { free(buf); buf = 0; + stride_length = 0; } return 0; }