From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: Lennert Buytenhek <buytenh@gnu.org>
Cc: linux-kernel@vger.kernel.org, netdev@oss.sgi.com
Subject: [PATCH] Re: [2.6.0, pktgen] divide-by-zero
Date: Sun, 18 Jan 2004 16:48:02 +0100 [thread overview]
Message-ID: <20040118154802.GE10397@wohnheim.fh-wedel.de> (raw)
In-Reply-To: <20031231111316.GA10218@gnu.org>
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,
next prev parent reply other threads:[~2004-01-18 15:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-31 11:13 [2.6.0, pktgen] divide-by-zero Lennert Buytenhek
2004-01-18 15:48 ` Jörn Engel [this message]
2004-01-18 23:15 ` [PATCH] " Robert Olsson
2004-01-19 17:24 ` David S. Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040118154802.GE10397@wohnheim.fh-wedel.de \
--to=joern@wohnheim.fh-wedel.de \
--cc=buytenh@gnu.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).