bin/130056: Have nfsstat use strtonum instead of atoi

Steve Kreuzer skreuzer at exit2shell.com
Tue Dec 30 15:40:01 UTC 2008


>Number:         130056
>Category:       bin
>Synopsis:       Have nfsstat use strtonum instead of atoi
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 30 15:40:00 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Steve Kreuzer
>Release:        FreeBSD 7.1-PRERELEASE amd64
>Organization:
>Environment:
System: FreeBSD slurry.exit2shell.com 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #3: Mon Nov 24 14:01:09 EST 2008 root at simon.sddi.net:/usr/obj/usr/src/sys/KERNEL amd64

>Description:
	nfsstat uses atoi for -w option. The attached patch will replace aoi
	and use strtonum instead
>How-To-Repeat:
	
>Fix:

--- nfsstat_strtonum_patch.txt begins here ---
Index: nfsstat.c
===================================================================
RCS file: /usr/share/cvs/freebsd/src/usr.bin/nfsstat/nfsstat.c,v
retrieving revision 1.22
diff -u -r1.22 nfsstat.c
--- nfsstat.c	18 Oct 2007 16:38:07 -0000	1.22
+++ nfsstat.c	30 Dec 2008 14:36:56 -0000
@@ -100,6 +100,7 @@
 	int serverOnly = -1;
 	int ch;
 	char *memf, *nlistf;
+	const char *errstr;
 	char errbuf[_POSIX2_LINE_MAX];
 
 	interval = 0;
@@ -116,7 +117,10 @@
 			widemode = 1;
 			break;
 		case 'w':
-			interval = atoi(optarg);
+			interval = (u_int)strtonum(optarg, 0, 1000, &errstr);
+			if (errstr)
+				errx(1, "invalid interval %s: %s",
+					optarg, errstr);
 			break;
 		case 'c':
 			clientOnly = 1;
@@ -141,7 +145,9 @@
 #define	BACKWARD_COMPATIBILITY
 #ifdef	BACKWARD_COMPATIBILITY
 	if (*argv) {
-		interval = atoi(*argv);
+		interval = (u_int)strtonum(*argv, 0, 1000, &errstr);
+		if (errstr)
+			errx(1, "invalid interval %s: %s", *argv, errstr);
 		if (*++argv) {
 			nlistf = *argv;
 			if (*++argv)
--- nfsstat_strtonum_patch.txt ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list