From: Darrick J. Wong Date: Fri, 14 Mar 2014 13:35:01 +0000 (-0400) Subject: libext2fs: fix 64bit overflow in ext2fs_block_alloc_stats_range X-Git-Tag: v1.43-WIP-2015-05-18~306 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b052dc1c8db93c32dea57f8b84b33367bac31b5b;p=thirdparty%2Fe2fsprogs.git libext2fs: fix 64bit overflow in ext2fs_block_alloc_stats_range In ext2fs_block_alloc_stats_range(), the quantity "-inuse * n" is calculated as a signed 32-bit quantity. Unfortunately, gcc (4.6.3 on Ubuntu 12.04) doesn't sign-extend this quantity to fill the blk64_t parameter that ext2fs_free_blocks_count_add() wants, so the end result is that the superblock gets a ridiculously huge free block count. Changing the declaration of 'n' to blk64_t seems to fix this. Signed-off-by: Darrick J. Wong Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c index 5bb86ef76..4feb24d6a 100644 --- a/lib/ext2fs/alloc_stats.c +++ b/lib/ext2fs/alloc_stats.c @@ -129,7 +129,7 @@ void ext2fs_block_alloc_stats_range(ext2_filsys fs, blk64_t blk, while (num) { int group = ext2fs_group_of_blk2(fs, blk); blk64_t last_blk = ext2fs_group_last_block2(fs, group); - blk_t n = num; + blk64_t n = num; if (blk + num > last_blk) n = last_blk - blk + 1;