Skip to content

net:dns-sd: fix handling of mutliple questions per query #89339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions subsys/net/lib/dns/dns_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,36 +1017,30 @@
}
}

if (query_size <= DNS_MSG_HEADER_SIZE) {
NET_DBG("query size %zu is less than DNS_MSG_HEADER_SIZE %d", query_size,
DNS_MSG_HEADER_SIZE);
return -EINVAL;
}

query += DNS_MSG_HEADER_SIZE;
query_size -= DNS_MSG_HEADER_SIZE;
offset = DNS_MSG_HEADER_SIZE;
offset = 0;
dns_sd_create_wildcard_filter(record);
/* valid record must have non-NULL port */
record->port = &dns_sd_port_zero;

if (query[0] == '.') {

Check warning on line 1025 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

subsys/net/lib/dns/dns_sd.c:1025 please, no spaces at the start of a line
query++;

Check failure on line 1026 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

subsys/net/lib/dns/dns_sd.c:1026 code indent should use tabs where possible

Check warning on line 1026 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

subsys/net/lib/dns/dns_sd.c:1026 please, no spaces at the start of a line
}

Check warning on line 1027 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

subsys/net/lib/dns/dns_sd.c:1027 please, no spaces at the start of a line

/* also counts labels */
for (i = 0, qlabels = 0; query_size > 0;) {

Check warning on line 1030 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SUSPECT_CODE_INDENT

subsys/net/lib/dns/dns_sd.c:1030 suspect code indent for conditional statements (8, 8)
qsize = *query;
++offset;
++query;
--query_size;

qsize = 0;

Check failure on line 1031 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

subsys/net/lib/dns/dns_sd.c:1031 code indent should use tabs where possible

Check warning on line 1031 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

subsys/net/lib/dns/dns_sd.c:1031 please, no spaces at the start of a line
while (qsize < query_size && query[qsize] != '.' && query[qsize] != '\0') {

Check failure on line 1032 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

subsys/net/lib/dns/dns_sd.c:1032 code indent should use tabs where possible

Check warning on line 1032 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

subsys/net/lib/dns/dns_sd.c:1032 please, no spaces at the start of a line

Check warning on line 1032 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SUSPECT_CODE_INDENT

subsys/net/lib/dns/dns_sd.c:1032 suspect code indent for conditional statements (8, 20)
qsize++;
}

Check warning on line 1034 in subsys/net/lib/dns/dns_sd.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TABSTOP

subsys/net/lib/dns/dns_sd.c:1034 Statements should start on a tabstop
if (qsize == 0) {
NET_DBG("empty label in query");
++query;
--query_size;
++offset;
break;
}

++qlabels;
if (qsize >= query_size) {
NET_DBG("claimed query size %zu > query buffer size %zu", qsize,
query_size);
return -EINVAL;
}

if (qsize >= size[i]) {
NET_DBG("qsize %zu >= size[%zu] %zu", qsize, i, size[i]);
Expand All @@ -1064,6 +1058,15 @@
offset += qsize;
query += qsize;
query_size -= qsize;

if (query_size && *query == '.') {
++query;
--query_size;
++offset;
} else if (strlen(query) == 0) {
/* end of query string */
break;
}
}

/* write-out the actual number of labels in 'n' */
Expand Down
7 changes: 2 additions & 5 deletions subsys/net/lib/dns/mdns_responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ static void send_sd_response(int sock,
sa_family_t family,
struct sockaddr *src_addr,
size_t addrlen,
struct dns_msg_t *dns_msg,
struct net_buf *result)
{
struct net_if *iface;
Expand Down Expand Up @@ -502,8 +501,7 @@ static void send_sd_response(int sock,
}
}

ret = dns_sd_query_extract(dns_msg->msg,
dns_msg->msg_size, &filter, label, size, &n);
ret = dns_sd_query_extract(result->data, result->len, &filter, label, size, &n);
if (ret < 0) {
NET_DBG("unable to extract query (%d)", ret);
return;
Expand Down Expand Up @@ -663,8 +661,7 @@ static int dns_read(int sock,
result, qtype);
} else if (IS_ENABLED(CONFIG_MDNS_RESPONDER_DNS_SD)
&& qtype == DNS_RR_TYPE_PTR) {
send_sd_response(sock, family, src_addr, addrlen,
&dns_msg, result);
send_sd_response(sock, family, src_addr, addrlen, result);
}

} while (--queries);
Expand Down
Loading