netdev
[Top] [All Lists]

[PATCH] Re: [2.6.0, pktgen] divide-by-zero

To: Lennert Buytenhek <buytenh@xxxxxxx>
Subject: [PATCH] Re: [2.6.0, pktgen] divide-by-zero
From: Jörn Engel <joern@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 18 Jan 2004 16:48:02 +0100
Cc: linux-kernel@xxxxxxxxxxxxxxx, netdev@xxxxxxxxxxx
In-reply-to: <20031231111316.GA10218@xxxxxxx>
References: <20031231111316.GA10218@xxxxxxx>
Sender: netdev-bounce@xxxxxxxxxxx
User-agent: Mutt/1.3.28i
On Wed, 31 December 2003 06:13:16 -0500, Lennert Buytenhek wrote:
> 
> When generating packets with pktgen with count=10, I get a divide-by-zero
> oops in inject().
> 
> Line 273 in net/core/pktgen.c seems unsafe:
>       __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 1000);
> 
> What if total < 1000 ?

Since noone else seemed to care, try this patch.  Against -test11,
yeah, I'm lazy again.

Jörn

-- 
Time? What's that? Time is only worth what you do with it.
-- Theo de Raadt

--- old/net/core/pktgen.c       2003-11-26 21:44:47.000000000 +0100
+++ new/net/core/pktgen.c       2004-01-18 16:27:10.000000000 +0100
@@ -720,7 +720,9 @@
 
        {
                char *p = info->result;
-               __u64 pps = (__u32)(info->sofar * 1000) / ((__u32)(total) / 
1000);
+               __u32 safe_total = (__u32)(total) / 1000;
+               safe_total += 1 - (!!safe_total); /* avoid divide-by-zero */
+               __u64 pps = (__u32)(info->sofar * 1000) / safe_total;
                __u64 bps = pps * 8 * (info->pkt_size + 4); /* take 32bit 
ethernet CRC into account */
                p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu 
(%dbyte,%dfrags) %llupps %lluMb/sec (%llubps)  errors: %llu",
                             (unsigned long long) total,


<Prev in Thread] Current Thread [Next in Thread>