Repository navigation
fix: escape dots and backslashes in labels read from packets - #540
Conversation
write_name and ServiceInfo::new treat "\." as a dot inside a label (RFC 6763 section 4.3), but read_labels appended each label unescaped. A question for an instance name with dots never matched the registered service, so SRV, TXT and ANY questions for it went unanswered. read_labels now escapes "." and "\" inside a label. A browsed fullname therefore keeps its escapes and equals the registered fullname. Escaping makes the text longer than the name on the wire, so the MAX_NAME_BYTES check now counts wire bytes in a separate wire_len. Without that, a legal name with many dots was rejected and its packet dropped. Fixes keepsimple1#536
keepsimple1
left a comment
There was a problem hiding this comment.
Thanks for this PR! The fix itself looks good.
There's one gap this fix exposes. Before the fix, a peer's record name never matched our escaped probe name for an instance with dots, so conflict detection never fired for such an instance. Now it does, and the conflict path renames the record with name_change (and hostname_change for A/AAAA). Both split the name on every ., including escaped ones:
name_change(r"L\.A\.R\.A Hub._lara._tcp.local.")
split('.') → ["L\", "A\", "R\", "A Hub", "_lara", "_tcp", "local", ""]
→ r"L\ (2).A\.R\.A Hub._lara._tcp.local."
on the wire: ["L\ (2)", "A.R.A Hub", "_lara", "_tcp", "local"]
The expected result is L\.A\.R\.A Hub (2)._lara._tcp.local..
Could you include a fix and a test in this PR? Or, if you would like to have it fixed in a separate PR, then open a new issue to track that.
To move forward, I've opened #546 to track the remaining gap. I will merge this PR for now. |
Since #540, a fullname read from the network keeps its RFC 6763 escapes, e.g. "L\.A\.R\.A Hub._lara._tcp.local.". Add a public instance_name_unescaped() that returns the first label of a fullname unescaped ("L.A.R.A Hub"). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #536
write_nameandServiceInfo::newtreat\.as a dot inside a label (RFC 6763 section 4.3), butread_labelsappended each label unescaped. A question for an instance name with dots therefore never matched the registered service, and SRV, TXT and ANYquestions for it went unanswered.
read_labelsnow escapes.and\inside a label, so a name read from a packet uses the same form thatwrite_nameparses. The answer owner (add_answer_of_servicereuses the question's name) is then written as the original single label too.Two things to check in review
L.A.R.A Hub._lara._tcp.local.from a browse event now getsL\.A\.R\.A Hub._lara._tcp.local..test_rfc6763_utf8_network_integrationexpected the old form, so I changed it.MAX_NAME_BYTESusedname.len(), which escaping makes longer than the name on the wire. A legal name with many dots would have been rejected and its whole packet dropped, soread_labelsandfollow_pointernow carry awire_lencount. The limit itself is unchanged.Tests
test_incoming_label_with_dot_is_escaped: aara._tcp.local(one label with dots) reads back asL.A.R.A Hub._lara._tcp.local.`.test_incoming_name_limit_ignores_escapes: ytes once escaped still parses.test_incoming_name_over_limit_is_rejected: a name above 255 bytes on the wire is still rejected.test_incoming_name_with_merged_labels_does_not_panic(Panic in write_utf8 (assert s.len() < 64) kills mDNS_daemon thread permanently on a ≥64-byte DNS label from the LAN #483): with the backslash escaped, the two labels no longer merge, so thetest now checks that the question is re-emitted by
test_rfc6763_utf8_network_integration: checks that the browsed fullname equals the registered fullname exactly.cargo testpasses on Windows 11 againstmain((mdns_test), 8 shutdown, 3 address-parsing and 4doc tests.
--all-featurespasses too (90 unit).cargo fmt --check, both CI clippy commands andcargo docare clean.Checked live (0.21.6 with the escaping change,
wire_lencount): a QU SRV query for the singlelabel
L.A.R.A Hubis answered with the SRV and A records. Without the change there was no response.