summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libnetutils')
-rw-r--r--libnetutils/packet.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libnetutils/packet.c b/libnetutils/packet.c
index e53a4c84f..9ecdd4f4e 100644
--- a/libnetutils/packet.c
+++ b/libnetutils/packet.c
@@ -218,6 +218,20 @@ int receive_packet(int s, struct dhcp_msg *msg)
218 * to construct the pseudo header used in the checksum calculation. 218 * to construct the pseudo header used in the checksum calculation.
219 */ 219 */
220 dhcp_size = ntohs(packet.udp.len) - sizeof(packet.udp); 220 dhcp_size = ntohs(packet.udp.len) - sizeof(packet.udp);
221 /*
222 * check validity of dhcp_size.
223 * 1) cannot be negative or zero.
224 * 2) src buffer contains enough bytes to copy
225 * 3) cannot exceed destination buffer
226 */
227 if ((dhcp_size <= 0) ||
228 ((int)(nread - sizeof(struct iphdr) - sizeof(struct udphdr)) < dhcp_size) ||
229 ((int)sizeof(struct dhcp_msg) < dhcp_size)) {
230#if VERBOSE
231 ALOGD("Malformed Packet");
232#endif
233 return -1;
234 }
221 saddr = packet.ip.saddr; 235 saddr = packet.ip.saddr;
222 daddr = packet.ip.daddr; 236 daddr = packet.ip.daddr;
223 nread = ntohs(packet.ip.tot_len); 237 nread = ntohs(packet.ip.tot_len);