Skip to content
Permalink
Browse files

net/llmnr: Fix LLMNR answer creation

- answer offset was 1 byte off.
- request offset, when copied into the answer, was off as well.

Fixes #16142

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
  • Loading branch information...
tbursztyka authored and jukkar committed May 28, 2019
1 parent e5cedca commit 11a8b42d8b3af819913cf2ee0020e43f6c3cb2e8
Showing with 7 additions and 9 deletions.
  1. +7 −9 subsys/net/lib/dns/llmnr_responder.c
@@ -189,20 +189,20 @@ static void add_question(struct net_buf *query, enum dns_rr_type qtype)
*prev = strlen(prev) - 1;
}

offset = DNS_MSG_HEADER_SIZE + query->len;
offset = DNS_MSG_HEADER_SIZE + query->len + 1;
UNALIGNED_PUT(htons(qtype), (u16_t *)(query->data+offset));

offset += DNS_QTYPE_LEN;
UNALIGNED_PUT(htons(DNS_CLASS_IN), (u16_t *)(query->data+offset));
}

static void add_answer(struct net_buf *query, u32_t ttl,
static int add_answer(struct net_buf *query, u32_t ttl,
u16_t addr_len, const u8_t *addr)
{
const u16_t q_len = query->len + DNS_QTYPE_LEN + DNS_QCLASS_LEN;
const u16_t q_len = query->len + 1 + DNS_QTYPE_LEN + DNS_QCLASS_LEN;
u16_t offset = DNS_MSG_HEADER_SIZE + q_len;

memcpy(query->data + offset, query->data, q_len);
memcpy(query->data + offset, query->data + DNS_MSG_HEADER_SIZE, q_len);
offset += q_len;

UNALIGNED_PUT(htonl(ttl), query->data + offset);
@@ -212,6 +212,8 @@ static void add_answer(struct net_buf *query, u32_t ttl,
offset += DNS_RDLENGTH_LEN;

memcpy(query->data + offset, addr, addr_len);

return offset + addr_len;
}

static int create_answer(struct net_context *ctx,
@@ -236,11 +238,7 @@ static int create_answer(struct net_context *ctx,

add_question(query, qtype);

add_answer(query, LLMNR_TTL, addr_len, addr);

query->len += DNS_MSG_HEADER_SIZE +
(DNS_QTYPE_LEN + DNS_QCLASS_LEN) * 2 +
DNS_TTL_LEN + DNS_RDLENGTH_LEN + addr_len + query->len;
query->len = add_answer(query, LLMNR_TTL, addr_len, addr);

return 0;
}

0 comments on commit 11a8b42

Please sign in to comment.
You can’t perform that action at this time.