Skip to content

fix: keep escaped dots inside first label in name_change/hostname_change (fix #546) - #547

Merged
keepsimple1 merged 5 commits into
keepsimple1:mainfrom
Sealdot:fix-escaped-dot-first-label
Nov 19, 2026
Merged

keepsimple1 merged 5 commits into
keepsimple1:mainfrom
Sealdot:fix-escaped-dot-first-label

Conversation

@Sealdot

@Sealdot Sealdot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

name_change and hostname_change take the first label with original.split('.'), which also splits on a dot escaped as \. (RFC 6763 §4.3). For a conflicted instance like L\.A\.R\.A Hub._lara._tcp.local., the rename produced L\ (2).A\.R\.A Hub._lara._tcp.local. — an extra label, a different instance — and the result could not round-trip through write_name, so queries for the renamed instance still went unanswered. hostname_change had the same bug: my\.host.local. → my\-2.host.local. instead of my\.host-2.local..

Fix

New split_first_label scans for the first unescaped dot — a backslash escapes the following character, so \\. still terminates the label — and the (n)/-n suffix is applied inside the real first label. The rest of the name is kept verbatim instead of re-joining on dots.

Tests

New escaped-dot cases in test_name_change/test_hostname_change (exactly the examples in the issue, plus the \\. backslash-escape edge): cargo test --lib _change → 3/3 pass on Rust 1.97.

AI assistance: the change and tests were prepared with an AI coding agent.

Update (commit 9920041): shared label splitter, addressing review feedback + #550

Following the suggestion in #550, the RFC 6763 §4.3 boundary rule now lives in exactly one place: a new EscapedLabels iterator in dns_parser.rs yields each escaped label slice (empty ones included). parse_escaped_name unescapes each slice and drops the empties; split_first_label takes the first slice and keeps the escaped remainder. Boundary and unescape behavior are unchanged.

Review feedback addressed:

  • A name whose first label is empty (e.g. ._lara._tcp.local.) now gets the rename suffix inside that label, restoring the pre-PR result (2)._lara._tcp.local. — the fallback that appended (2) to the end of the whole name is removed.
  • split_first_label now documents its return value.

New tests cover every case listed in #550 (a\.b, a\\.b, a\x.b, a\\\.b, trailing \, leading ., ..) asserting both the slices and the parse_escaped_name output, plus the empty-first-label rename cases. cargo test --lib 94/94, doc 4/4, clippy --all-targets clean (cargo 1.97.1, macOS arm64).

…nge (fix keepsimple1#546)

Both rename helpers took the first label via split('.'), which also
splits on dots escaped as \. per RFC 6763 section 4.3. A probe conflict on
an instance like L\.A\.R\.A Hub._lara._tcp.local. produced L\ (2).A\.R\.A Hub
with an extra label instead of L\.A\.R\.A Hub (2)._lara._tcp.local., and the
result could not round-trip through write_name, leaving the renamed
instance unanswerable.

split_first_label now scans for the first unescaped dot (a backslash
escapes the next character, so \\. still terminates the label) and the
suffix is appended inside the real first label.

AI assistance: prepared with an AI coding agent; new escaped-dot cases
pass in test_name_change and test_hostname_change.
Rephrase the doc comment so a backslash-escaped token does not
start a continuation line, which clippy parses as an unindented list
item (CI: Lint and Documentation, windows-2025 clippy step).
@Sealdot
Sealdot force-pushed the fix-escaped-dot-first-label branch from 8a8cea7 to e621597 Compare November 11, 2026 04:00
The doc block for name_change was left above split_first_label, which also triggered clippy::doc_lazy_continuation after the list items.
@Sealdot
Sealdot marked this pull request as ready for review November 14, 2026 00:35
@Sealdot

Sealdot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

CI is green and the change is complete on my side — marking ready for review.

Comment thread src/service_daemon.rs Resolved
Comment thread src/service_daemon.rs Resolved

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! Overall looks good. Comments inline.

Add EscapedLabels, an iterator over the escaped label slices of a name, so the RFC 6763 section 4.3 boundary rule lives in exactly one place. parse_escaped_name now unescapes each yielded slice and drops the empty ones; split_first_label takes the first slice and keeps the escaped remainder. Boundary and unescape behavior are unchanged, including empty labels and unrecognized escapes.

Also fix the rename fallback for a name whose first label is empty: `._lara._tcp.local.` now keeps its suffix inside that label, restoring the pre-PR result ` (2)._lara._tcp.local.` instead of `._lara._tcp.local. (2)`, and document the return value of split_first_label. Addresses review feedback; implements the shared splitter suggested in keepsimple1#550.

AI assistance: Cognition Devin CLI agent (SWE-2 High).

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@keepsimple1
keepsimple1 merged commit ea547cd into keepsimple1:main Nov 19, 2026
6 checks passed
Sealdot added a commit to Sealdot/mdns-sd that referenced this pull request Nov 19, 2026
When a probe conflict triggers name_change/hostname_change, the appended ` (n)`/`-n` suffix can push the first label past MAX_LABEL_BYTES, after which write_name rejects every packet and the service silently vanishes.

Shorten the base so the label with the new suffix still fits, like mDNSResponder: measure wire bytes via escape-aware helpers in dns_parser.rs (\. and \\ count as one byte, never cut inside a pair or a UTF-8 char), trim a trailing space/`-`, and recompute on every rename as ` (9)` -> ` (10)` grows the suffix. register_service now rejects an instance label over 63 wire bytes up front instead of failing silently on the network.

Fixes keepsimple1#549.

Rebased onto main @ ea547cd (keepsimple1#547): the truncation is ported onto EscapedLabels/split_first_label so escaped first labels keep the suffix inside the label.

AI assistance: Cognition Devin CLI agent (SWE-2 High).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants