From: Theodore Ts'o Date: Sun, 29 Dec 2013 03:25:11 +0000 (-0500) Subject: e2freefrag: avoid integer overflow when reporting free space statistics X-Git-Tag: v1.42.9~10 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=d05508956734d55f7ee286085a1f6570d11848b7;p=tools%2Fe2fsprogs.git e2freefrag: avoid integer overflow when reporting free space statistics An integer overflow could happen if the file system is large and has very large contiguous chunks of free space. Addresses-Debian-Bug: #718205 Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c index 58f1ff5..612ca44 100644 --- a/misc/e2freefrag.c +++ b/misc/e2freefrag.c @@ -172,10 +172,10 @@ static errcode_t get_chunk_info(ext2_filsys fs, struct chunk_info *info, /* Display chunk information in KB */ if (info->real_free_chunks) { - info->min = (info->min * fs->blocksize) >> 10; - info->max = (info->max * fs->blocksize) >> 10; - info->avg = (info->avg / info->real_free_chunks * - fs->blocksize) >> 10; + unsigned int scale = fs->blocksize >> 10; + info->min = info->min * scale; + info->max = info->max * scale; + info->avg = info->avg / info->real_free_chunks * scale; } else { info->min = 0; }