bin/142911: [patch] vmstat(8) -w should produce error message if fed a negative value

Bruce Evans brde at optusnet.com.au
Mon Jan 18 03:55:47 UTC 2010


On Sun, 17 Jan 2010, Efstratios Karatzas <gpf.kira at gmail.com> 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


More information about the freebsd-bugs mailing list