Date: Sun, 17 Jan 2010 17:14:13 GMT From: "Efstratios Karatzas <gpf.kira@gmail.com>" <gpf.kira@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/142911: [patch] vmstat(8) -w should produce error message if fed a negative value Message-ID: <201001171714.o0HHED1e001707@www.freebsd.org> Resent-Message-ID: <201001171720.o0HHK1IU082302@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 142911 >Category: bin >Synopsis: [patch] vmstat(8) -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:20:01 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: 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. >How-To-Repeat: > vmstat -w -1 > vmstat -w -32409 > vmstat -w abc >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. version of the file i've used: FBSDID("$FreeBSD: src/usr.bin/vmstat/vmstat.c,v 1.98.2.4 2009/11/06 20:33:53 jhb Exp $"); Patch attached with submission follows: --- vmstat.c 2010-01-17 18:01:12.000000000 +0200 +++ vmstat.orig.c 2010-01-17 17:59:02.000000000 +0200 @@ -244,8 +244,6 @@ break; case 'w': interval = atoi(optarg); - if ((int)interval < 1) - errx(1, "wait time < 1"); break; case 'z': todo |= ZMEMSTAT; >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001171714.o0HHED1e001707>