From: Darrick J. Wong Date: Fri, 2 Feb 2018 15:32:43 +0000 (-0600) Subject: mkfs: don't crash on dswidth overflow X-Git-Tag: v4.15.0-rc1~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=91c7d131631626eb701b149104aceae10ff1cb45;p=thirdparty%2Fxfsprogs-dev.git mkfs: don't crash on dswidth overflow 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 Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 5f1ac9fdd..7c9d148c0 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -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)) {