summaryrefslogtreecommitdiff
path: root/package/busybox/patches/450-truncated_ping_results.patch
blob: 34582c2ba9797cca6c029fcc1fd0728ce477522c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Index: busybox-1.4.2/networking/ping.c
===================================================================
--- busybox-1.4.2.orig/networking/ping.c	2007-06-04 13:21:31.931122400 +0200
+++ busybox-1.4.2/networking/ping.c	2007-06-04 13:21:36.518425024 +0200
@@ -70,7 +70,7 @@
 	struct sockaddr_in pingaddr;
 	struct icmp *pkt;
 	int pingsock, c;
-	char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
+	char packet[datalen + ICMP_MINLEN + MAXIPLEN + MAXICMPLEN];
 
 	pingsock = create_icmp_socket();
 
@@ -86,7 +86,7 @@
 	pkt->icmp_type = ICMP_ECHO;
 	pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
 
-	c = sendto(pingsock, packet, DEFDATALEN + ICMP_MINLEN, 0,
+	c = sendto(pingsock, packet, datalen + ICMP_MINLEN, 0,
 			   (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in));
 
 	if (c < 0) {
@@ -274,6 +274,10 @@
 		++nreceived;
 		tp = (struct timeval *) icmppkt->icmp_data;
 
+		/* If packet is too short, results will be truncated */
+		if (sz < (ICMP_MINLEN + sizeof(tv.tv_sec) + sizeof(tv.tv_usec)))
+			return;
+
 		if ((tv.tv_usec -= tp->tv_usec) < 0) {
 			--tv.tv_sec;
 			tv.tv_usec += 1000000;