Subject: bin/29226: /etc/daily pipes >32bit integers from netstat to awk, which can't deal with them
To: None <,>
From: None <>
List: netbsd-bugs
Date: 02/04/2005 08:17:00
>Number:         29226
>Category:       bin
>Synopsis:       /etc/daily pipes >32bit integers from netstat to awk, which can't deal with them
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 04 08:17:00 +0000 2005
>Originator:     Arto Selonen
>Release:        NetBSD-current, 2.99.15 from ~20050131
NetBSD blah 2.99.15 NetBSD 2.99.15 (BLAH) #77: Mon Jan 31 10:27:44 EET 2005  blah@blah:/obj/sys/arch/i386/compile/BLAH i386

/etc/daily's check_network may pipe 'netstat -inv' output to awk
for further processing. However, netstat may produces numbers larger
than 32 bits, and awk seems to only handle up to 32bit signed integers.

Here is a sample 'netstat -inv' that triggers the problem:
(I have edited it to fit better, and replaced addresses; the problem
is in the size of the packet counters)

Name Mtu  Network   Address      Ipkts      Ierrs Opkts      Oerrs Colls
wm0  1500 <Link>    re:pl:ac:ed  6333370853 0     7202788621 0     0
wm0  1500 10.2.3/24     6333370853 0     7202788621 0     0

And this is what /etc/daily check_network reports:
(again output white space edited for readability; prolem is
in the number's representation, ie. overflow)

Name   Ipkts       Ierrs Opkts       Oerrs  Colls
wm0    -2147483648 0     -2147483648 0      0

% echo "9876543210" | awk '{ printf("%10d\n", $1);}'

% echo "9876543210" | awk '{ printf("%12lu\n", $1);}'

% echo "9876543210" | awk '{ printf("%12qu\n", $1);}'
awk: weird printf conversion %12q
 input record number 1, file 
 source line number 1

(1) Teach awk 64bit number handling, including quad conversions.
(2) Fix printf field formatting in /etc/daily accordingly.


(1) Replace awk in /etc/daily with something that can deal with
    large numbers

This is how a Mandrake 10.0 Linux awk (presumably GNU awk) handles it:

% echo "9876543210" | awk '{ printf("%12lu\n", $1);}'

This is really a awk/64bit problem, but as it has so far only surfaced
in /etc/daily usage, I could argue that the problem is not awk's
integer sizes, but rather using *awk* in /etc/daily.

Fixing awk instead of just /etc/daily will probably benefit other
instances of awk usage as well.