Skip to content

Commit 11a8b42

Browse files
Tomasz Bursztykajukkar
authored andcommitted
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 <[email protected]>
1 parent e5cedca commit 11a8b42

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

subsys/net/lib/dns/llmnr_responder.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,20 @@ static void add_question(struct net_buf *query, enum dns_rr_type qtype)
189189
*prev = strlen(prev) - 1;
190190
}
191191

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

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

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

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

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

214214
memcpy(query->data + offset, addr, addr_len);
215+
216+
return offset + addr_len;
215217
}
216218

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

237239
add_question(query, qtype);
238240

239-
add_answer(query, LLMNR_TTL, addr_len, addr);
240-
241-
query->len += DNS_MSG_HEADER_SIZE +
242-
(DNS_QTYPE_LEN + DNS_QCLASS_LEN) * 2 +
243-
DNS_TTL_LEN + DNS_RDLENGTH_LEN + addr_len + query->len;
241+
query->len = add_answer(query, LLMNR_TTL, addr_len, addr);
244242

245243
return 0;
246244
}

0 commit comments

Comments
 (0)