bin/142912: [patch] nfsstat(1) -w should produce error message if fed a negative value

Efstratios Karatzas <gpf.kira at> gpf.kira at
Sun Jan 17 17:30:02 UTC 2010

>Number:         142912
>Category:       bin
>Synopsis:       [patch] nfsstat(1) -w should produce error message if fed a negative value
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 17 17:30:01 UTC 2010
>Originator:     Efstratios Karatzas <gpf.kira at>
>Release:        FreeBSD 8.0-STABLE i386
FreeBSD Eternal_Crusader 8.0-STABLE FreeBSD 8.0-STABLE #0: Thu Jan 7 04:08:09 EET 2010     root at bt:/usr/obj/usr/src/sys/GENERIC i386
nfsstat(1) -w should produce an error message and exit when fed a negative numerical value or a non numerical value at all, in which case atoi simply returns 0. This is the way iostat(8) handles this situation.

If we do not check for a negative value, then the negative value we are fed becomes an extremely large unsigned int and the thread will sleep(3) for a long time indeed.

> nfsstat -w -1
> nfsstat -w -3049
> nfsstat -w abc
apply my patch, all we need is a simple check if the value is less than 1. This way an error message also occurs if we could not parse a number, since the return value in that case is 0.

version of the file i've used:

rcsid[] = "$FreeBSD: src/usr.bin/nfsstat/nfsstat.c,v 1.29 2009/12/13 03:14:06 delphij Exp$";

Patch attached with submission follows:

--- nfsstat.c	2010-01-17 18:34:34.000000000 +0200
+++ nfsstat.orig.c	2010-01-17 18:32:38.000000000 +0200
@@ -126,8 +126,6 @@
 		case 'w':
 			interval = atoi(optarg);
-			if ((int)interval < 1)
-				errx(1, "wait time < 1");
 		case 'c':
 			clientOnly = 1;


More information about the freebsd-bugs mailing list