summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2018-12-06 10:35:41 +1100
committerJes Sorensen <jsorensen@fb.com>2018-12-06 07:56:21 -0500
commit085df42259cba7863cd6ebe5cd0d8492ac5b869e (patch)
tree95eabb294b2dd047a097a16b852d9da52c44326e
parent563ac108659980b3d1e226fe416254a86656235f (diff)
downloadmdadm-085df42259cba7863cd6ebe5cd0d8492ac5b869e.tar.gz
Grow: avoid overflow in compute_backup_blocks()
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>
-rw-r--r--Grow.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Grow.c b/Grow.c
index 4436a4d6..76f82c07 100644
--- 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;
}