]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Grow: avoid overflow in compute_backup_blocks()
authorNeilBrown <neilb@suse.com>
Wed, 5 Dec 2018 23:35:41 +0000 (10:35 +1100)
committerJes Sorensen <jsorensen@fb.com>
Thu, 6 Dec 2018 12:56:21 +0000 (07:56 -0500)
With a chunk size of 16Meg and data drive count of 8,
this calculate can easily overflow the 'int' type that
is used for the multiplications.
So force it to use "long" instead.

Reported-and-tested-by: Ed Spiridonov <edo.rus@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Grow.c

diff --git a/Grow.c b/Grow.c
index 4436a4d6bd4cdff4fe3ebe03c2a1f3eebdf33196..76f82c075e38b3b718d2b80ae6ec08e877dd58a5 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -1196,7 +1196,8 @@ unsigned long compute_backup_blocks(int nchunk, int ochunk,
        /* Find GCD */
        a = GCD(a, b);
        /* LCM == product / GCD */
-       blocks = (ochunk/512) * (nchunk/512) * odata * ndata / a;
+       blocks = (unsigned long)(ochunk/512) * (unsigned long)(nchunk/512) *
+               odata * ndata / a;
 
        return blocks;
 }