summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorStefan Sperling <stsp@cvs.openbsd.org>2019-11-26 17:51:34 +0000
committerStefan Sperling <stsp@cvs.openbsd.org>2019-11-26 17:51:34 +0000
commit17057babb497ab9c1b4a3c47d6399751831eccb9 (patch)
treecbb6700cea711aff666164ab7db47fd11a045b7f /usr.bin
parent571a2f69c8b1f4c51fb1fb240af2efc48f59e214 (diff)
Prevent divide-by zero in tcpbench(1). Found while testing iwm(4).
#0 0x000004c27b9051a9 in udp_process_slice (fd=<optimized out>, event=<optimized out>, v_sc=0x4c55279f500) at /usr/src/usr.bin/tcpbench/tcpbench.c:606 606 pps = (sc->udp_slice_pkts * 1000) / since_last; (gdb) p since_last $1 = 0 ok benno@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tcpbench/tcpbench.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/usr.bin/tcpbench/tcpbench.c b/usr.bin/tcpbench/tcpbench.c
index ac79861e0af..bda10f5a0ce 100644
--- a/usr.bin/tcpbench/tcpbench.c
+++ b/usr.bin/tcpbench/tcpbench.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcpbench.c,v 1.59 2018/09/28 19:01:52 bluhm Exp $ */
+/* $OpenBSD: tcpbench.c,v 1.60 2019/11/26 17:51:33 stsp Exp $ */
/*
* Copyright (c) 2008 Damien Miller <djm@mindrot.org>
@@ -565,6 +565,8 @@ tcp_process_slice(int fd, short event, void *bula)
total_elapsed = t_diff.tv_sec * 1000 + t_diff.tv_usec / 1000;
timersub(&t_cur, &sc->t_last, &t_diff);
since_last = t_diff.tv_sec * 1000 + t_diff.tv_usec / 1000;
+ if (since_last == 0)
+ continue;
bwperc = (sc->bytes * 100.0) / mainstats.slice_bytes;
mbps = (sc->bytes * 8) / (since_last * 1000.0);
slice_mbps += mbps;
@@ -602,6 +604,8 @@ udp_process_slice(int fd, short event, void *v_sc)
total_elapsed = t_diff.tv_sec * 1000 + t_diff.tv_usec / 1000;
timersub(&t_cur, &sc->t_last, &t_diff);
since_last = t_diff.tv_sec * 1000 + t_diff.tv_usec / 1000;
+ if (since_last == 0)
+ return;
slice_mbps = (sc->bytes * 8) / (since_last * 1000.0);
pps = (sc->udp_slice_pkts * 1000) / since_last;
if (slice_mbps > mainstats.peak_mbps)