Skip to content

name_change/hostname_change can make a first label longer than 63 bytes #549

Done

Description

@keepsimple1

When a probe finds a conflict, name_change and hostname_change (in src/service_daemon.rs) add (n) or -n to the first label. Neither one checks that the label still fits in 63 bytes. write_name rejects any label longer than MAX_LABEL_BYTES with WriteError::NameTooLong (src/dns_parser.rs), so the renamed name can never be sent.

Example: an instance whose first label is 60 bytes on the wire becomes 64 bytes after name_change adds (2). Every probe and announcement for the new name fails to encode. The service never appears on the network, and the app gets no error.

This was already the case before #547. #547 makes it more likely, because instance names with dots now take the rename path (see #546).

Suggested fix

Shorten the base name so the suffix fits, as mDNSResponder does:

  1. Separate the base from the existing (n) or -n suffix and work out the new suffix. Then cut the base to 63 - suffix.len() bytes as measured on the wire. Recompute this on every rename, because (9) → (10) adds a byte.
  2. Measure wire bytes, not escaped bytes: \. and \\ each count as 1 byte, and any other \x counts as 1 byte plus the length of x, the same way parse_escaped_name counts. Only cut where both of these hold:
    • not in the middle of an escape pair (cutting \. down to \ would escape the next character);
    • on a UTF-8 character boundary.
  3. After cutting, trim trailing spaces in name_change (avoids Foo (2)) and a trailing - in hostname_change (avoids foo--2).
  4. Optional: reject a first label over 63 wire bytes in register_service, so the caller gets an error up front instead of a silent failure on the network.

This needs another function that understands the escape rules, alongside parse_escaped_name and split_first_label (#547). It may be worth one shared helper in dns_parser.rs for splitting labels and measuring wire length.

Tests

  • A 63-byte label is cut to 59 bytes plus (2).
  • (9) → (10) at the limit, so the base loses one more byte.
  • A multi-byte UTF-8 character falls right at the cut point.
  • \. falls right at the cut point, so the whole escape pair is dropped.
  • hostname_change with a 63-byte first label.

Activity

  1. added 3 commits that reference this issue on Nov 18, 2026
    65c519b
    674afe4
    56d2f63
  2. added a commit that references this issue on Nov 25, 2026
    27f1214
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