Skip to content

write_name compression can point to the wrong name when a label contains a dot #541

Closed

Description

@keepsimple1

DnsOutPacket::write_name records each name suffix it has written so later names can compress against it. The key for that map is built by joining the unescaped labels with .:

let remaining: String = labels[i..].join(".");

A dot inside a label (RFC 6763 section 4.3) looks the same in that key as a dot between labels. So two different names can share a key, and the second one is written as a pointer to the first, which turns it into a different name on the wire.

To reproduce (on main, fc0c597):

let mut out = DnsOutgoing::new(0);
out.add_question(r"L\.A.B.local.", RRType::PTR); // labels: "L.A", "B", "local"
out.add_question("L.A.B.local.", RRType::PTR);   // labels: "L", "A", "B", "local"
let packets = out.to_packets(MAX_PKT_DEFAULT, IPV6);
println!("{:02x?}", packets[0].as_bytes());

Both names get the key L.A.B.local. The packet after the header is:

03 "L.A" 01 "B" 05 "local" 00  00 0c 00 01    first question, written in full
c0 0c                          00 0c 00 01    second question, pointer to offset 12

The second question should start with 01 "L" 01 "A" 01 "B" 05 "local" 00. A receiver decodes it as the first name instead.

The same applies to a suffix: x.L.A.B.local. written after the first name also compresses against it at L.A.B.local.

Impact: it needs two names in one packet that differ only in where a label boundary falls, so it should be rare. Names learned from the network are re-emitted (for example as known answers), so a peer can cause it. The result is a wrong name in the packet, not a crash.

Possible fix: build the key so that label boundaries stay distinct, for example by escaping . and \ in each label before joining, or by keying on the labels themselves.

Noticed while reviewing #540. This is separate from that PR and from #536: the key is built only on the write path.

Activity

  1. added a commit that references this issue on Nov 4, 2026
    ec74531
  2. added a commit that references this issue on Nov 14, 2026
    1d9aa6f
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