Fix SERVFAIL crash on TXT records with valueless keys

zeroconf represents a TXT attribute with no "=" (a bare boolean flag,
valid per RFC 6763 §6.4) or an empty value as properties[key] = None.
Reconstructing the TXT record blindly did b"%s=%s" % (key, None),
which raises TypeError since bytes %-formatting rejects None. The
exception propagated out of the deferToThread call and Twisted
answered with SERVFAIL instead of the TXT record, silently breaking
resolution for any service whose TXT record includes a bare key
(e.g. some _rfb._tcp/screen-sharing advertisements).

Found by diagnosing a real screen-sharing "impossible de resoudre"
failure over a WireGuard-tunneled deployment: dig showed SRV
resolving fine but TXT returning SERVFAIL for the same instance,
which is why dns-sd -L (needs both) never completed even after
flushing the client-side mDNSResponder cache.
This commit is contained in:
2026-08-05 12:46:32 +02:00
parent 8270d2d7ca
commit e45560f763
+2 -1
View File
@@ -143,7 +143,8 @@ class DynamicResolver(object):
order.append(kv[0])
i += length
data = [b"%s=%s" % (p, info.properties[p]) for p in sorted(info.properties, key=lambda k: order.index(k) if k in order else 1000)]
data = [(b"%s=%s" % (p, v)) if (v := info.properties[p]) is not None else p
for p in sorted(info.properties, key=lambda k: order.index(k) if k in order else 1000)]
now = current_time_millis()
cached = self.zeroconf.cache.get_by_details(localname, _TYPE_TXT, _CLASS_IN)
record_ttl = int(cached.get_remaining_ttl(now)) if cached else ttl