diff options
author | Dmitry Shmidt <dimitrysh@google.com> | 2010-01-08 10:47:26 -0800 |
---|---|---|
committer | Dmitry Shmidt <dimitrysh@google.com> | 2010-01-08 10:47:26 -0800 |
commit | 938bc384f44031877543765a9ae18c764f5da9c8 (patch) | |
tree | 3c5d3e2749b7b1bef613a1283373d61945db7421 /net.c | |
parent | b22386a3de85d94030c7071760f4a5e3368bfbe5 (diff) | |
download | android_external_dhcpcd-938bc384f44031877543765a9ae18c764f5da9c8.tar.gz android_external_dhcpcd-938bc384f44031877543765a9ae18c764f5da9c8.tar.bz2 android_external_dhcpcd-938bc384f44031877543765a9ae18c764f5da9c8.zip |
dhcpcd: Upgrade from 4.0.1 to 4.0.15
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'net.c')
-rw-r--r-- | net.c | 54 |
1 files changed, 26 insertions, 28 deletions
@@ -112,9 +112,9 @@ get_netmask(uint32_t addr) dst = htonl(addr); if (IN_CLASSA(dst)) return ntohl(IN_CLASSA_NET); - if (IN_CLASSB (dst)) + if (IN_CLASSB(dst)) return ntohl(IN_CLASSB_NET); - if (IN_CLASSC (dst)) + if (IN_CLASSC(dst)) return ntohl(IN_CLASSC_NET); return 0; @@ -634,44 +634,42 @@ get_udp_data(const uint8_t **data, const uint8_t *udp) } int -valid_udp_packet(const uint8_t *data) +valid_udp_packet(const uint8_t *data, size_t data_len) { struct udp_dhcp_packet packet; - uint16_t bytes; - uint16_t ipsum; - uint16_t iplen; - uint16_t udpsum; - struct in_addr source; - struct in_addr dest; - int retval = 0; - - memcpy(&packet, data, sizeof(packet)); - bytes = ntohs(packet.ip.ip_len); - ipsum = packet.ip.ip_sum; - iplen = packet.ip.ip_len; - udpsum = packet.udp.uh_sum; + uint16_t bytes, udpsum; - if (0 != checksum(&packet.ip, sizeof(packet.ip))) { + if (data_len > sizeof(packet)) { + errno = EINVAL; + return -1; + } + memcpy(&packet, data, data_len); + if (checksum(&packet.ip, sizeof(packet.ip)) != 0) { errno = EINVAL; return -1; } - packet.ip.ip_sum = 0; - memcpy(&source, &packet.ip.ip_src, sizeof(packet.ip.ip_src)); - memcpy(&dest, &packet.ip.ip_dst, sizeof(packet.ip.ip_dst)); - memset(&packet.ip, 0, sizeof(packet.ip)); + bytes = ntohs(packet.ip.ip_len); + if (data_len < bytes) { + errno = EINVAL; + return -1; + } + udpsum = packet.udp.uh_sum; packet.udp.uh_sum = 0; - - packet.ip.ip_p = IPPROTO_UDP; - memcpy(&packet.ip.ip_src, &source, sizeof(packet.ip.ip_src)); - memcpy(&packet.ip.ip_dst, &dest, sizeof(packet.ip.ip_dst)); + packet.ip.ip_hl = 0; + packet.ip.ip_v = 0; + packet.ip.ip_tos = 0; packet.ip.ip_len = packet.udp.uh_ulen; - if (udpsum && udpsum != checksum(&packet, bytes)) { + packet.ip.ip_id = 0; + packet.ip.ip_off = 0; + packet.ip.ip_ttl = 0; + packet.ip.ip_sum = 0; + if (udpsum && checksum(&packet, bytes) != udpsum) { errno = EINVAL; - retval = -1; + return -1; } - return retval; + return 0; } int |