Whamcloud - gitweb
e2freefrag: avoid integer overflow when reporting free space statistics
authorTheodore Ts'o <tytso@mit.edu>
Sun, 29 Dec 2013 03:25:11 +0000 (22:25 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 29 Dec 2013 03:25:11 +0000 (22:25 -0500)
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" <tytso@mit.edu>
misc/e2freefrag.c

index 58f1ff5..612ca44 100644 (file)
@@ -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;
        }