From nobody@FreeBSD.org  Sun Jan 17 17:30:44 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 32204106568B
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 17 Jan 2010 17:30:44 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 1BAD08FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 17 Jan 2010 17:30:44 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0HHUhiv015126
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 17 Jan 2010 17:30:43 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o0HHUhnc015125;
	Sun, 17 Jan 2010 17:30:43 GMT
	(envelope-from nobody)
Message-Id: <201001171730.o0HHUhnc015125@www.freebsd.org>
Date: Sun, 17 Jan 2010 17:30:43 GMT
From: "Efstratios Karatzas <gpf.kira@gmail.com>" <gpf.kira@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] netstat(1) -w should produce error message if fed a negative value
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         142913
>Category:       bin
>Synopsis:       [patch] netstat(1) -w should produce error message if fed a negative value
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 17 17:40:00 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Efstratios Karatzas <gpf.kira@gmail.com>
>Release:        FreeBSD 8.0-STABLE i386
>Organization:
>Environment:
FreeBSD Eternal_Crusader 8.0-STABLE FreeBSD 8.0-STABLE #0: Thu Jan 7 04:08:09 EET 2010     root@bt:/usr/obj/usr/src/sys/GENERIC i386
>Description:
netstat(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 we will waste a lot of time sleeping before we are finally awaken. 
If I'm not mistaken, we 'll wake up when the timer underflows and eventually turns 0.

>How-To-Repeat:
> netstat -w -1
> netstat -w abc
> netstat -w -30941
>Fix:
apply my patch. all we need is a check if the value we are fed is a positive integer greater than 1. This way, an error message also occurs if we were not able to parse an integer since atoi(3) returns 0 in that case.

version of the file I used:

__FBSDID("$FreeBSD: src/usr.bin/netstat/main.c,v 1.103 2010/01/11 03:00:17 delphij Exp $");


Patch attached with submission follows:

--- main.c	2010-01-17 17:30:56.000000000 +0200
+++ main.orig.c	2010-01-17 17:29:52.000000000 +0200
@@ -469,8 +469,6 @@
 			break;
 		case 'w':
 			interval = atoi(optarg);
-			if (interval < 1)
-				errx(1, "wait time < 1");
 			iflag = 1;
 			break;
 		case 'x':


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