Subject: bin/434: df overflows on some integer calculations
To: None <gnats-admin>
From: None <jarle@idt.unit.no>
List: netbsd-bugs
Date: 08/22/1994 12:50:05
>Number:         434
>Category:       bin
>Synopsis:       df claims some filesystems have negative numbers of blocks.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 22 12:50:04 1994
>Originator:     Jarle Greipsland
>Organization:
Free Hardware Foundation, UnLtd.
"	"
>Release:        NetBSD 1.0_BETA
>Environment:
	
System: NetBSD darling.idt.unit.no 1.0_BETA NetBSD 1.0_BETA (DARLING) #0: Tue Aug 2 11:22:27 MET DST 1994 jarle@darling.idt.unit.no:/usr/src/sys/arch/i386/compile/DARLING i386


>Description:
Some calculations internal to df overflows, most notably when some huge
NFS-mounted disks are stat'ed.  Each value in itself fits in the designated 
'long' (or equivalent) storage space, but 'var1 * factor' doesn't.
	
>How-To-Repeat:
NFS-mount a 9GB disk, and run df.
	
>Fix:
Make df use quad_t during these calculations and outputs.  There may be more 
than the one that immediately came to view.
Apply diff:
*** /usr/src/bin/df/df.c.orig	Mon Aug 22 20:57:25 1994
--- /usr/src/bin/df/df.c	Mon Aug 22 21:01:46 1994
***************
*** 211,220 ****
  	(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
  	used = sfsp->f_blocks - sfsp->f_bfree;
  	availblks = sfsp->f_bavail + used;
! 	(void)printf(" %*ld %7ld %7ld", headerlen,
! 	    sfsp->f_blocks * sfsp->f_bsize / blocksize,
! 	    used * sfsp->f_bsize / blocksize,
! 	    sfsp->f_bavail * sfsp->f_bsize / blocksize);
  	(void)printf(" %5.0f%%",
  	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
  	if (iflag) {
--- 211,220 ----
  	(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
  	used = sfsp->f_blocks - sfsp->f_bfree;
  	availblks = sfsp->f_bavail + used;
! 	(void)printf(" %*qd %7qd %7qd", headerlen,
! 	    (quad_t)sfsp->f_blocks * sfsp->f_bsize / blocksize,
! 	    (quad_t)used * sfsp->f_bsize / blocksize,
! 	    (quad_t)sfsp->f_bavail * sfsp->f_bsize / blocksize);
  	(void)printf(" %5.0f%%",
  	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
  	if (iflag) {
	
>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------