From owner-freebsd-bugs@FreeBSD.ORG Mon Jan 18 03:55:47 2010 Return-Path: Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 43E78106566C; Mon, 18 Jan 2010 03:55:47 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail07.syd.optusnet.com.au (mail07.syd.optusnet.com.au [211.29.132.188]) by mx1.freebsd.org (Postfix) with ESMTP id B6B3E8FC14; Mon, 18 Jan 2010 03:55:46 +0000 (UTC) Received: from c220-239-227-214.carlnfd1.nsw.optusnet.com.au (c220-239-227-214.carlnfd1.nsw.optusnet.com.au [220.239.227.214]) by mail07.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o0I3tfRL015356 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 18 Jan 2010 14:55:43 +1100 Date: Mon, 18 Jan 2010 14:55:41 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: "Efstratios Karatzas " In-Reply-To: <201001171714.o0HHED1e001707@www.freebsd.org> Message-ID: <20100118144216.X66411@delplex.bde.org> References: <201001171714.o0HHED1e001707@www.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-bugs@FreeBSD.org, freebsd-gnats-submit@FreeBSD.org Subject: Re: bin/142911: [patch] vmstat(8) -w should produce error message if fed a negative value X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jan 2010 03:55:47 -0000 On Sun, 17 Jan 2010, Efstratios Karatzas wrote: >> Description: > vmstat(8) -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. Please use line lengths of considerably less than 168 characters. I'm editing this with a slightly wrong $TERMCAP and the line wrap from the long lines is even more horrible than usual. There is another bad atoi() for the wait interval, in the BACKWARD_COMPATIBILITY ifdef, which is a non-optional option. There are other bad atoi()s in the file. One has a bounds check and neither has a type error to break negative values. >> Fix: > 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. -w 0 used to sort of work -- it was equivalent to not specifying an interval. Maybe some scripts or fingers depend on this. Probably lots still depends on the undocumented BACKWARD_COMPATIBILITY behaviour (vmstat 1 == vmstat -w 1), so this non-optional option can never be removed. The other bad atoi()s don't use this trick, so they give a garbage result for parse errors. Bruce