quota(1): Fix calculation overflow and underflow

For very large quotas, do the multiplication as a 64 bit value to avoid
overflow.

For very small block sizes (smaller than DEV_BSIZE), multiple first
before dividing by block size to avoid underflow.

PR:		227496
Submitted by:	Per Andersson <pa AT chalmers.se>
Sponsored by:	Dell EMC Isilon
This commit is contained in:
Conrad Meyer 2018-04-16 19:33:04 +00:00
parent 52c0983128
commit 404d2fee56
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332632

View file

@ -621,14 +621,14 @@ getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype)
gettimeofday(&tv, NULL);
/* blocks*/
dqp->dqb_bhardlimit =
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit *
(gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
((uint64_t)gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit *
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize) / DEV_BSIZE;
dqp->dqb_bsoftlimit =
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit *
(gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
((uint64_t)gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit *
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize) / DEV_BSIZE;
dqp->dqb_curblocks =
gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks *
(gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
((uint64_t)gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks *
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize) / DEV_BSIZE;
/* inodes */
dqp->dqb_ihardlimit =
gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit;