From 5eff45cac064cb14a034add77ac13ac4251fadbd Mon Sep 17 00:00:00 2001 From: Our Air Quality Date: Tue, 18 Jul 2017 00:43:22 +1000 Subject: [PATCH] Correct a few uses of sizeof(ip6_addr_t) to sizeof(ip6_addr_p_t) The ip6_addr_t structure may have an addition slot so is not necessarily the size of an ipv6 address, so some uses of sizeof(ip6_addr_t) were not correct. Signed-off-by: goldsimon --- src/apps/mdns/mdns.c | 6 +++--- src/core/dns.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 824ec9aa..7c3f0238 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -528,7 +528,7 @@ mdns_build_reverse_v6_domain(struct mdns_domain *domain, const ip6_addr_t *addr) } memset(domain, 0, sizeof(struct mdns_domain)); ptr = (const u8_t *) addr; - for (i = sizeof(ip6_addr_t) - 1; i >= 0; i--) { + for (i = sizeof(ip6_addr_p_t) - 1; i >= 0; i--) { char buf; u8_t byte = ptr[i]; int j; @@ -1163,7 +1163,7 @@ mdns_add_aaaa_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct net struct mdns_domain host; mdns_build_host_domain(&host, NETIF_TO_HOST(netif)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with AAAA record\n")); - return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif))->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_t), NULL); + return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif))->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_p_t), NULL); } /** Write a x.y.z.ip6.arpa -> hostname.local PTR RR to outpacket */ @@ -1628,7 +1628,7 @@ mdns_handle_question(struct mdns_packet *pkt) #endif } else if (match & REPLY_HOST_AAAA) { #if LWIP_IPV6 - if (ans.rd_length == sizeof(ip6_addr_t) && + if (ans.rd_length == sizeof(ip6_addr_p_t) && /* TODO this clears all AAAA responses if first addr is set as known */ pbuf_memcmp(pkt->pbuf, ans.rd_offset, netif_ip6_addr(pkt->netif, 0), ans.rd_length) == 0) { LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: AAAA\n")); diff --git a/src/core/dns.c b/src/core/dns.c index 25b295a7..12acda7f 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -1265,17 +1265,17 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, } #endif /* LWIP_IPV4 */ #if LWIP_IPV6 - if ((ans.type == PP_HTONS(DNS_RRTYPE_AAAA)) && (ans.len == PP_HTONS(sizeof(ip6_addr_t)))) { + if ((ans.type == PP_HTONS(DNS_RRTYPE_AAAA)) && (ans.len == PP_HTONS(sizeof(ip6_addr_p_t)))) { #if LWIP_IPV4 && LWIP_IPV6 if (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype)) #endif /* LWIP_IPV4 && LWIP_IPV6 */ { - ip6_addr_t ip6addr; + ip6_addr_p_t ip6addr; /* read the IP address after answer resource record's header */ - if (pbuf_copy_partial(p, &ip6addr, sizeof(ip6_addr_t), res_idx) != sizeof(ip6_addr_t)) { + if (pbuf_copy_partial(p, &ip6addr, sizeof(ip6_addr_p_t), res_idx) != sizeof(ip6_addr_p_t)) { goto memerr; /* ignore this packet */ } - ip_addr_copy_from_ip6(dns_table[i].ipaddr, ip6addr); + ip_addr_copy_from_ip6_packed(dns_table[i].ipaddr, ip6addr); pbuf_free(p); /* handle correct response */ dns_correct_response(i, lwip_ntohl(ans.ttl));