Skip to content

Share one escape-aware label splitter between split_first_label and parse_escaped_name #550

Closed

Description

@keepsimple1

The rule for where a label ends in an escaped name (RFC 6763 §4.3) is now written out in two places:

  • DnsOutPacket::parse_escaped_name (src/dns_parser.rs) splits a name into unescaped labels for write_name. It treats only \. and \\ as escapes. Any other \x stays as a literal backslash followed by x.
  • split_first_label (src/service_daemon.rs, added in fix: keep escaped dots inside first label in name_change/hostname_change (fix #546) #547) finds the first unescaped dot for name_change and hostname_change. It treats a backslash as escaping whatever character follows it.

Today both give the same label boundaries for every input. The two scanners disagree only on \ followed by a character other than . or \, and that never decides where a label ends. But they agree by coincidence, not by design. If one changes (for example, to support RFC 1035 \DDD decimal escapes) and the other doesn't, the rename code and the wire encoder will split names differently. That is the failure #546 fixed: a renamed record goes out with an extra label.

#549 would add a third function that needs the same rules: measuring a label's length on the wire so a renamed label can be cut to 63 bytes.

Why not call parse_escaped_name from split_first_label?

  • It returns unescaped labels. name_change needs the escaped form and its byte offsets so it can keep the rest of the name exactly as it is. Escaping the output again doesn't give the original back: a non-standard \x comes back as \\x, which changes the stored name.
  • It drops empty labels. For ._lara._tcp.local. it reports _lara as the first label instead of "".

Suggested approach

Add one pub(crate) helper in dns_parser.rs that works on the escaped string and returns where each label starts and ends. It could be an iterator over escaped label slices, or a function that returns the byte offset of each unescaped dot. Each part of the escape rules then lives in exactly one place:

Tests

  • Both callers find the same unescaped-dot positions for a\.b, a\\.b, a\x.b, a\\\.b, a trailing \, a leading ., and ... (parse_escaped_name then drops the empty labels.)
  • Existing test_name_change, test_hostname_change and write_name tests still pass.

Activity

  1. keepsimple1 commented on Nov 19, 2026

    @keepsimple1
    OwnerAuthor

    Fixed by #547

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions