Whamcloud - gitweb
libext2fs: fix block-mapped file punch
authorAndreas Dilger <andreas.dilger@intel.com>
Mon, 30 Nov 2015 20:26:21 +0000 (15:26 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 30 Nov 2015 20:26:21 +0000 (15:26 -0500)
commite158db537754ae1ffb3ec6184051bd1a4226937a
tree9e79eed592585f8427ca320be052615404158465
parentf680db654b2f095712f2528dc178eea5cfd6401f
libext2fs: fix block-mapped file punch

If ext2fs_punch() was called with "end = ~0ULL" to indicate truncate
to the end of file it tried to compute "count" for ext2fs_punch_ind()
based on "start" and "end", but incorrectly passed "count = ~0U" even
when "start" was non-zero, causing an overflow in some cases.

The calling convention for ext2fs_punch_ind() was also gratuitously
different from ext2fs_punch() and ext2fs_punch_extent(), passing
"count" instead of "end" as the last parameter.  Fix this by passing
it "end" like the other functions, and handle "count" internally.

Add checks to ext2fs_punch_ind() if "end" is at or beyond the 2^32
indirect block limit so the 32-bit internal variables don't overflow.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/punch.c