Skip to content

Commit

Permalink
Bug appneta#210 avoid overflow with -M option
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen committed Mar 17, 2017
1 parent e6c8240 commit fc1e261
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/defines.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#define COUNTER unsigned long
#define COUNTER_SPEC "%lu"
#endif
#define COUNTER_OVERFLOW_RISK (((COUNTER)~0) >> 20)

#include "common/list.h"
#include "common/cidr.h"
Expand Down
12 changes: 10 additions & 2 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,11 +1155,19 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta,
*/
now_us = TIMSTAMP_TO_MICROSEC(sent_timestamp);
if (now_us) {
COUNTER next_tx_us;
COUNTER bps = options->speed.speed;
COUNTER bits_sent = ((ctx->stats.bytes_sent + len) * 8);
/* bits * 1000000 divided by bps = microseconds */
COUNTER next_tx_us = (bits_sent * 1000000) / bps;
COUNTER tx_us = now_us - *start_us;
/*
* bits * 1000000 divided by bps = microseconds
*
* ensure there is no overflow in cases where bits_sent is very high
*/
if (bits_sent > COUNTER_OVERFLOW_RISK && bps > 500000)
next_tx_us = (bits_sent * 1000) / bps * 1000;
else
next_tx_us = (bits_sent * 1000000) / bps;
if (next_tx_us > tx_us) {
NANOSEC_TO_TIMESPEC((next_tx_us - tx_us) * 1000, &ctx->nap);
} else if (tx_us > next_tx_us) {
Expand Down
3 changes: 0 additions & 3 deletions src/tcprewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ rewrite_packets(tcpedit_t *tcpedit, pcap_t *pin, pcap_dumper_t *pout)
int rcode;
#ifdef ENABLE_FRAGROUTE
int frag_len, proto;
#ifdef DEBUG
int i;
#endif
#endif

pkthdr_ptr = &pkthdr;
Expand Down

0 comments on commit fc1e261

Please sign in to comment.