layers/dns: preserve wire label boundaries for names with literal dots (DNS-SD/mDNS)#1237
Open
gainskills wants to merge 1 commit into
Open
layers/dns: preserve wire label boundaries for names with literal dots (DNS-SD/mDNS)#1237gainskills wants to merge 1 commit into
gainskills wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
4259612 to
537a803
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
gopacket decodes DNS names to dotted
[]byteand the serializer rebuilds the wirename by splitting on every
.. That corrupts any DNS name whose single labelcontains a literal dot — common in DNS-SD/mDNS service-instance names. A
foo.barinstance label in
foo.bar._tcp.localdecodes fine but re-serializes as two labels(
foo,bar), producing a malformed packet, even when the name wasn't modified.Refernce
Fix
lazily — only when a label actually contains
.or\— so ordinary names addno allocations.
round-trip); otherwise it parses the name as presentation form where
.separateslabels, with
\.,\\, and\DDDescapes to embed literal bytes in a label.escape) instead of silently emitting a malformed packet.
This is a generic DNS fix, not mDNS-specific. It covers the DNS name fields gopacket
decodes: question/owner names and NS, CNAME, PTR, SOA, MX, and SRV RDATA. Non-name
RDATA (A/AAAA, TXT, URI, OPT) is unaffected.
Compatibility
Public API unchanged — same
[]bytefields, no new exported symbols. Decoded bytes andordinary names (
example.com) serialize identically. The only behavior change: in aconstructed or modified name,
\.now means a literal dot, which only affectscallers that opt into the escape syntax.
Testing
23 new tests (preservation across all covered fields, compression, decode→mutate→encode,
escapes, invalid-name errors, zero-copy buffer-reuse safety) plus a decode→serialize
fuzz target.
go test ./layers,go vet, andgofmtclean.