Fix truncated pings results when packets are too small. Also check for packet maximum...
[openwrt.git] / package / busybox / patches / 450-truncated_ping_results.patch
1 --- busybox-1.4.1/networking/ping.c 2007-01-24 22:34:34.000000000 +0100
2 +++ busybox-1.4.1.new/networking/ping.c 2007-02-28 20:35:59.000000000 +0100
3 @@ -70,7 +70,7 @@
4 struct sockaddr_in pingaddr;
5 struct icmp *pkt;
6 int pingsock, c;
7 - char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
8 + char packet[datalen + MAXIPLEN + MAXICMPLEN];
9
10 pingsock = create_icmp_socket();
11
12 @@ -86,7 +86,7 @@
13 pkt->icmp_type = ICMP_ECHO;
14 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
15
16 - c = sendto(pingsock, packet, DEFDATALEN + ICMP_MINLEN, 0,
17 + c = sendto(pingsock, packet, datalen + ICMP_MINLEN, 0,
18 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
19
20 if (c < 0) {
21 @@ -257,8 +257,8 @@
22
23 gettimeofday(&tv, NULL);
24
25 - /* discard if too short */
26 - if (sz < (datalen + ICMP_MINLEN))
27 + /* discard if too short / long */
28 + if (sz < (datalen + ICMP_MINLEN) || sz > (MAXICMPLEN))
29 return;
30
31 /* check IP header */
32 @@ -274,6 +274,10 @@
33 ++nreceived;
34 tp = (struct timeval *) icmppkt->icmp_data;
35
36 + /* If packet is too short, results will be truncated */
37 + if (sz < (ICMP_MINLEN + sizeof(tv.tv_sec) + sizeof(tv.tv_usec)))
38 + return;
39 +
40 if ((tv.tv_usec -= tp->tv_usec) < 0) {
41 --tv.tv_sec;
42 tv.tv_usec += 1000000;
This page took 0.044629 seconds and 5 git commands to generate.