]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: don't crash on dswidth overflow
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 2 Feb 2018 15:32:43 +0000 (09:32 -0600)
committerEric Sandeen <sandeen@redhat.com>
Fri, 2 Feb 2018 15:32:43 +0000 (09:32 -0600)
I ran mkfs.xfs -d su=1048576,sw=$((18 * 1048576)), forgetting that sw
takes a multiple of su (unlike swidth which takes any space unit).  I
was surprised when we hit a floating point exception, which I traced
back to an integer overflow when we calculate swidth from dsw.

So, do the 64-bit multiplication so we can detect the overflow and
complain about it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
mkfs/xfs_mkfs.c

index 5f1ac9fddff1b9dd2b253646513cdcbdb9219ce5..7c9d148c020fbfc8922d3dc633ded9d85f8ccb2f 100644 (file)
@@ -2211,6 +2211,7 @@ calc_stripe_factors(
        struct cli_params       *cli,
        struct fs_topology      *ft)
 {
+       long long int   big_dswidth;
        int             dsunit = 0;
        int             dswidth = 0;
        int             lsunit = 0;
@@ -2251,7 +2252,14 @@ _("data su must be a multiple of the sector size (%d)\n"), cfg->sectorsize);
                }
 
                dsunit  = (int)BTOBBT(dsu);
-               dswidth = dsunit * dsw;
+               big_dswidth = (long long int)dsunit * dsw;
+               if (big_dswidth > INT_MAX) {
+                       fprintf(stderr,
+_("data stripe width (%lld) is too large of a multiple of the data stripe unit (%d)\n"),
+                               big_dswidth, dsunit);
+                       usage();
+               }
+               dswidth = big_dswidth;
        }
 
        if (dsunit && (dswidth % dsunit != 0)) {