From 404d2fee5650e4e7201cfd3b627d5b63619e5c73 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Mon, 16 Apr 2018 19:33:04 +0000 Subject: [PATCH] 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 Sponsored by: Dell EMC Isilon --- usr.bin/quota/quota.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/usr.bin/quota/quota.c b/usr.bin/quota/quota.c index fc97111676d..8e4bb8a6f40 100644 --- a/usr.bin/quota/quota.c +++ b/usr.bin/quota/quota.c @@ -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;