Skip to content

Commit 29b52a8

Browse files
committed
net: mdns + dns_sd: fix regression that breaks ptr queries
While adding support for service type enumeration, a regression was introduced which prevented mDNS ptr query responses. 1. There was an off-by-one error with label size checking 2. Valid queries were failing to match in `dns_rec_match()` due to not checking for either NULL or 0 "wildcard" port Fixes #39284 Signed-off-by: Christopher Friedt <[email protected]>
1 parent af4c3bc commit 29b52a8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

subsys/net/lib/dns/dns_sd.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,9 @@ bool dns_sd_rec_match(const struct dns_sd_rec *record,
951951

952952
/* check for the "wildcard" pointer */
953953
if (filt_label != NULL) {
954-
if (!checkers[i](filt_label)) {
954+
if (!checkers[i](rec_label)) {
955955
LOG_WRN("invalid %s label: '%s'",
956-
names[i], filt_label);
956+
names[i], rec_label);
957957
return false;
958958
}
959959

@@ -965,8 +965,10 @@ bool dns_sd_rec_match(const struct dns_sd_rec *record,
965965
}
966966

967967
/* check for the "wildcard" port */
968-
if (filter->port != NULL && *(record->port) != *(filter->port)) {
969-
return false;
968+
if (filter->port != NULL && *(filter->port) != 0) {
969+
if (*(record->port) != *(filter->port)) {
970+
return false;
971+
}
970972
}
971973

972974
return true;
@@ -1032,8 +1034,8 @@ int dns_sd_query_extract(const uint8_t *query, size_t query_size, struct dns_sd_
10321034
return -EINVAL;
10331035
}
10341036

1035-
if (qsize > size[i] - 1) {
1036-
NET_DBG("qsize %zu > size[%zu] - 1 %zu", qsize, i, size[i] - 1);
1037+
if (qsize > size[i]) {
1038+
NET_DBG("qsize %zu > size[%zu] %zu", qsize, i, size[i]);
10371039
return -ENOBUFS;
10381040
}
10391041

subsys/net/lib/dns/mdns_responder.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ static void send_sd_response(struct net_context *ctx,
303303
{
304304
int ret;
305305
const struct dns_sd_rec *record;
306-
struct dns_sd_rec filter;
306+
/* filter must be zero-initialized for "wildcard" port */
307+
struct dns_sd_rec filter = {0};
307308
struct sockaddr dst;
308309
socklen_t dst_len;
309310
bool service_type_enum = false;

0 commit comments

Comments
 (0)