From cc155ebf243a900109613eae4c89a381aa545160 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Sat, 17 Mar 2018 11:10:10 -0700 Subject: [PATCH] vendor: update golang.org/x/net/dns/dnsmessage from upstream Updates to x/net git rev 24dd378 for CL 100055 Fixes #10622 Updates #16218 Change-Id: I99e26da7b908b36585a0379d9381030c01819b54 Reviewed-on: https://go-review.googlesource.com/101278 Run-TryBot: Ian Gudger TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- .../x/net/dns/dnsmessage/message.go | 10 ++++++++- .../x/net/dns/dnsmessage/message_test.go | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/vendor/golang_org/x/net/dns/dnsmessage/message.go b/src/vendor/golang_org/x/net/dns/dnsmessage/message.go index 0ab4aab2023..d8d3b034292 100644 --- a/src/vendor/golang_org/x/net/dns/dnsmessage/message.go +++ b/src/vendor/golang_org/x/net/dns/dnsmessage/message.go @@ -91,6 +91,7 @@ var ( errTooManyAdditionals = errors.New("too many Additionals to pack (>65535)") errNonCanonicalName = errors.New("name is not in canonical format (it must end with a .)") errStringTooLong = errors.New("character string exceeds maximum length (255)") + errCompressedSRV = errors.New("compressed name in SRV resource data") ) // Internal constants. @@ -1610,6 +1611,10 @@ func (n *Name) pack(msg []byte, compression map[string]int, compressionOff int) // unpack unpacks a domain name. func (n *Name) unpack(msg []byte, off int) (int, error) { + return n.unpackCompressed(msg, off, true /* allowCompression */) +} + +func (n *Name) unpackCompressed(msg []byte, off int, allowCompression bool) (int, error) { // currOff is the current working offset. currOff := off @@ -1645,6 +1650,9 @@ Loop: name = append(name, '.') currOff = endOff case 0xC0: // Pointer + if !allowCompression { + return off, errCompressedSRV + } if currOff >= len(msg) { return off, errInvalidPtr } @@ -2044,7 +2052,7 @@ func unpackSRVResource(msg []byte, off int) (SRVResource, error) { return SRVResource{}, &nestedError{"Port", err} } var target Name - if _, err := target.unpack(msg, off); err != nil { + if _, err := target.unpackCompressed(msg, off, false /* allowCompression */); err != nil { return SRVResource{}, &nestedError{"Target", err} } return SRVResource{priority, weight, port, target}, nil diff --git a/src/vendor/golang_org/x/net/dns/dnsmessage/message_test.go b/src/vendor/golang_org/x/net/dns/dnsmessage/message_test.go index c143d7e791c..052897f3cf5 100644 --- a/src/vendor/golang_org/x/net/dns/dnsmessage/message_test.go +++ b/src/vendor/golang_org/x/net/dns/dnsmessage/message_test.go @@ -158,6 +158,28 @@ func TestNamePackUnpack(t *testing.T) { } } +func TestIncompressibleName(t *testing.T) { + name := mustNewName("example.com.") + compression := map[string]int{} + buf, err := name.pack(make([]byte, 0, 100), compression, 0) + if err != nil { + t.Fatal("First packing failed:", err) + } + buf, err = name.pack(buf, compression, 0) + if err != nil { + t.Fatal("Second packing failed:", err) + } + var n1 Name + off, err := n1.unpackCompressed(buf, 0, false /* allowCompression */) + if err != nil { + t.Fatal("Unpacking incompressible name without pointers failed:", err) + } + var n2 Name + if _, err := n2.unpackCompressed(buf, off, false /* allowCompression */); err != errCompressedSRV { + t.Errorf("Unpacking compressed incompressible name with pointers: got err = %v, want = %v", err, errCompressedSRV) + } +} + func checkErrorPrefix(err error, prefix string) bool { e, ok := err.(*nestedError) return ok && e.s == prefix