Skip to content

Check name length against the wire form, not the presentation form - #223

Open
mrideout wants to merge 1 commit into
alexdalitz:masterfrom
mrideout:255-octet-limit
Open

Check name length against the wire form, not the presentation form#223
mrideout wants to merge 1 commit into
alexdalitz:masterfrom
mrideout:255-octet-limit

Conversation

@mrideout

Copy link
Copy Markdown
Contributor

The problem

Dnsruby::Name#initialize compares MaxNameLength (255) against the length of the dotted presentation form:

total_length = labels.length - 1
labels.each { |l| total_length += l.length }

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's dig, host and nslookup reject it with "ran out of space".

The fix

total_length = labels.length + 1

Label#length returns the decoded length, so escaped labels take care of themselves.

Tests

test_name_length did 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_message is new, covering the Message path 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 through encode/decode. Both fail without the fix. rake test passes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant