From 7cc35e41e71600113e5d2a07bc999052a6384d1e Mon Sep 17 00:00:00 2001 From: Maxime Henrion Date: Mon, 12 Apr 2004 13:02:21 +0000 Subject: [PATCH] Don't send the available space as is in the FSSTAT call. Under FreeBSD, we can have a negative available space value, but the corresponding fields in the NFS protocol are unsigned. So trnucate the value to 0 if it's negative, so that the client doesn't receive absurdly high values. Tested by: cognet --- sys/nfsserver/nfs_serv.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/nfsserver/nfs_serv.c b/sys/nfsserver/nfs_serv.c index e76fd5c18c3..258da54078d 100644 --- a/sys/nfsserver/nfs_serv.c +++ b/sys/nfsserver/nfs_serv.c @@ -3808,7 +3808,16 @@ nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, tval = (u_quad_t)sf->f_bfree; tval *= (u_quad_t)sf->f_bsize; txdr_hyper(tval, &sfp->sf_fbytes); - tval = (u_quad_t)sf->f_bavail; + /* + * Don't send negative values for available space, + * since this field is unsigned in the NFS protocol. + * Otherwise, the client would see absurdly high + * numbers for free space. + */ + if (sf->f_bavail < 0) + tval = 0; + else + tval = (u_quad_t)sf->f_bavail; tval *= (u_quad_t)sf->f_bsize; txdr_hyper(tval, &sfp->sf_abytes); sfp->sf_tfiles.nfsuquad[0] = 0; @@ -3823,7 +3832,10 @@ nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, sfp->sf_bsize = txdr_unsigned(sf->f_bsize); sfp->sf_blocks = txdr_unsigned(sf->f_blocks); sfp->sf_bfree = txdr_unsigned(sf->f_bfree); - sfp->sf_bavail = txdr_unsigned(sf->f_bavail); + if (sf->f_bavail < 0) + sfp->sf_bavail = 0; + else + sfp->sf_bavail = txdr_unsigned(sf->f_bavail); } nfsmout: if (vp)