From: Yu Watanabe Date: Wed, 8 Nov 2023 11:53:39 +0000 (+0900) Subject: resolve/mdns: do not append packets without records X-Git-Tag: v255-rc2~74^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6cfa4fc4ce8c72936c25a5f5ac55d2cb7c9cf337;p=thirdparty%2Fsystemd.git resolve/mdns: do not append packets without records Previously, if we have only max_rr cached entries, then an empty packet is appended. Prompted by #29168. --- diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index 7a1a1620aff..78665bc93be 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -1308,6 +1308,19 @@ int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p, usec_t ts, if (usec_sub_unsigned(j->until, ts) < j->rr->ttl * USEC_PER_SEC / 2) continue; + if (max_rr > 0 && ancount >= max_rr) { + DNS_PACKET_HEADER(p)->ancount = htobe16(ancount); + ancount = 0; + + r = dns_packet_new_query(&p->more, p->protocol, 0, true); + if (r < 0) + return r; + + p = p->more; + + max_rr = UINT_MAX; + } + r = dns_packet_append_rr(p, j->rr, 0, NULL, NULL); if (r == -EMSGSIZE) { if (max_rr == 0) @@ -1333,18 +1346,6 @@ int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p, usec_t ts, return r; ancount++; - if (max_rr > 0 && ancount >= max_rr) { - DNS_PACKET_HEADER(p)->ancount = htobe16(ancount); - ancount = 0; - - r = dns_packet_new_query(&p->more, p->protocol, 0, true); - if (r < 0) - return r; - - p = p->more; - - max_rr = UINT_MAX; - } } finalize: