[Toybox] [patch] fix 32bit overflowing issue of arping
Hyejin Kim
hj8296 at gmail.com
Tue Oct 6 02:56:44 PDT 2015
Hi. Rob.
In the pending code, arping has an 32bit overflowing issue when calculating
time delta
Plz, have a look.
---
toys/pending/arping.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/toys/pending/arping.c b/toys/pending/arping.c
index be43cab..a6f91b2 100644
--- a/toys/pending/arping.c
+++ b/toys/pending/arping.c
@@ -33,15 +33,12 @@ config ARPING
#include <netpacket/packet.h>
GLOBALS(
- long count;
- unsigned long time_out;
- char *iface;
- char *src_ip;
-
- int sockfd;
- unsigned long start, end;
- unsigned sent_at, sent_nr, rcvd_nr, brd_sent, rcvd_req, brd_rcv,
- unicast_flag;
+ long count, time_out;
+ char *iface, *src_ip;
+
+ int sockfd;
+ unsigned sent_nr, rcvd_nr, brd_sent, rcvd_req, brd_rcv, unicast_flag;
+ unsigned long long sent_at;
)
struct sockaddr_ll src_pk, dst_pk;
@@ -160,11 +157,11 @@ static void recv_from(struct sockaddr_ll *from, int
*recv_len)
arp_hdr->ar_op == htons(ARPOP_REPLY) ? "ply" : "quest",
inet_ntoa(s_ip), ether_ntoa((struct ether_addr *) p));
if (TT.sent_at) {
- unsigned delta;
+ unsigned long long delta;
struct timeval tval;
gettimeofday(&tval, NULL);
- delta = (tval.tv_sec * 1000000ULL + (tval.tv_usec)) - TT.sent_at;
+ delta = (tval.tv_sec * 1000000ULL + tval.tv_usec) - TT.sent_at;
xprintf(" %u.%03ums\n", delta / 1000, delta % 1000);
xflush();
}
@@ -182,18 +179,18 @@ static void recv_from(struct sockaddr_ll *from, int
*recv_len)
// Alarm signal Handle, send packets in one second interval.
static void send_signal(int sig)
{
- struct timeval start;
+ struct timeval tval;
+ static unsigned long long start, end;
- gettimeofday(&start, NULL);
- if (!TT.start)
- TT.end = TT.start = start.tv_sec * 1000 + start.tv_usec / 1000;
- else TT.end = start.tv_sec*1000 + start.tv_usec / 1000;
+ gettimeofday(&tval, NULL);
+ if (!start) end = start = tval.tv_sec * 1000 + tval.tv_usec / 1000;
+ else end = tval.tv_sec*1000 + tval.tv_usec / 1000;
if (toys.optflags & FLAG_c) {
if (!TT.count) done(0);
TT.count--;
}
- if ((toys.optflags & FLAG_w) && ((TT.end - TT.start) >
- ((TT.time_out)*1000))) done(0);
+ if ((toys.optflags & FLAG_w) && ((end - start) >
+ (TT.time_out*1000))) done(0);
send_packet();
alarm(1);
}
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20151006/2f76e101/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-fix-overflow-issue-when-calculating-time-on-arping.patch
Type: application/octet-stream
Size: 2515 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20151006/2f76e101/attachment-0004.obj>
More information about the Toybox
mailing list