Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaped names compression length mismatch #841

Closed
tmthrgd opened this issue Nov 28, 2018 · 1 comment
Closed

Escaped names compression length mismatch #841

tmthrgd opened this issue Nov 28, 2018 · 1 comment

Comments

@tmthrgd
Copy link
Collaborator

tmthrgd commented Nov 28, 2018

The following test case fails due to differences in escaping between PackDomainName and Len:

func TestMsgCompressionEscapingCompressionMap(t *testing.T) {
	msg := new(Msg)
	msg.Compress = true
	msg.SetQuestion("www.example.org.", TypeA)
	msg.Answer = append(msg.Answer, &NS{Hdr: RR_Header{Name: "ex\\097mple.org.", Rrtype: TypeNS, Class: ClassINET}, Ns: "ns.example.org."})

	predicted := msg.Len()
	buf, err := msg.Pack()
	if err != nil {
		t.Error(err)
	}
	if predicted != len(buf) {
		t.Fatalf("predicted compressed length is wrong: predicted %d, actual %d", predicted, len(buf))
	}
}

with:

--- FAIL: TestMsgCompressionEscapingCompressionMap (0.00s)
    length_test.go:398: predicted compressed length is wrong: predicted 61, actual 50

The problem is that \\097 is a perfectly valid escaping of a, PackDomainName handles this by putting the unescaped name (only the first label is unescaped) into the compression map, while the Len code puts the escaped name in the compression map. (This isn't effected by #833).

I'm not sure what the best way to fix this is, fixing this in Len would (I think) require extra allocations, and fixing this in PackDomainName is trickier than it might seem.

This is one of the corner cases I mentioned in #652 (comment).

@miekg
Copy link
Owner

miekg commented Nov 28, 2018 via email

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

No branches or pull requests

2 participants