Check name length against the wire form, not the presentation form - #223
Open
mrideout wants to merge 1 commit into
Open
Check name length against the wire form, not the presentation form#223mrideout wants to merge 1 commit into
mrideout wants to merge 1 commit into
Conversation
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.
The problem
Dnsruby::Name#initializecomparesMaxNameLength(255) against the length of the dotted presentation form:That adds up the label text plus the dots in between. On the wire a length octet replaces each dot, but there is one more label than there are dots, and a zero octet ends the name. So the wire form is always 2 octets longer.
The 255 comes from RFC 1035 Section 2.3.4, and RFC 2181 Section 11 spells out what counts toward it: a name is "limited to 255 octets (including the separators)", the separators being those length octets and the trailing zero. So names 1 or 2 octets over the limit got through and got encoded into real queries and responses. dnspython rejects such a name with
NameTooLong, and BIND'sdig,hostandnslookupreject it with "ran out of space".The fix
Label#lengthreturns the decoded length, so escaped labels take care of themselves.Tests
test_name_lengthdid not test what its name said. It built a name with a 253-character first label, which tripped the 63-octet label limit and never reached the name check, so it would have passed with that check deleted. I rewrote it to check that a 255-octet name is accepted and a 256-octet one is not.test_name_length_in_messageis new, covering theMessagepath the over-long names were reaching the wire through, in both directions: the 256-octet name is refused, and the 255-octet one still round-trips throughencode/decode. Both fail without the fix.rake testpasses.