Skip to content

Commit 73e4b50

Browse files
mateusz834gopherbot
authored andcommitted
dns/dnsmessage: allow name compression for SRV resource parsing
As per RFC 3597: Receiving servers MUST decompress domain names in RRs of well-known type, and SHOULD also decompress RRs of type RP, AFSDB, RT, SIG, PX, NXT, NAPTR, and SRV (although the current specification of the SRV RR in RFC2782 prohibits compression, RFC2052 mandated it, and some servers following that earlier specification are still in use). This change allows SRV resource decompression. Updates golang/go#36718 Updates golang/go#37362 Change-Id: I473c0d3803758e5b12886f378d2ed54bd5392144 GitHub-Last-Rev: 88d2e06 GitHub-Pull-Request: #199 Reviewed-on: https://go-review.googlesource.com/c/net/+/540375 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Auto-Submit: Damien Neil <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent b2208d0 commit 73e4b50

File tree

2 files changed

+1
-31
lines changed

2 files changed

+1
-31
lines changed

dns/dnsmessage/message.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ var (
273273
errTooManyAdditionals = errors.New("too many Additionals to pack (>65535)")
274274
errNonCanonicalName = errors.New("name is not in canonical format (it must end with a .)")
275275
errStringTooLong = errors.New("character string exceeds maximum length (255)")
276-
errCompressedSRV = errors.New("compressed name in SRV resource data")
277276
)
278277

279278
// Internal constants.
@@ -2028,10 +2027,6 @@ func (n *Name) pack(msg []byte, compression map[string]uint16, compressionOff in
20282027

20292028
// unpack unpacks a domain name.
20302029
func (n *Name) unpack(msg []byte, off int) (int, error) {
2031-
return n.unpackCompressed(msg, off, true /* allowCompression */)
2032-
}
2033-
2034-
func (n *Name) unpackCompressed(msg []byte, off int, allowCompression bool) (int, error) {
20352030
// currOff is the current working offset.
20362031
currOff := off
20372032

@@ -2076,9 +2071,6 @@ Loop:
20762071
name = append(name, '.')
20772072
currOff = endOff
20782073
case 0xC0: // Pointer
2079-
if !allowCompression {
2080-
return off, errCompressedSRV
2081-
}
20822074
if currOff >= len(msg) {
20832075
return off, errInvalidPtr
20842076
}
@@ -2549,7 +2541,7 @@ func unpackSRVResource(msg []byte, off int) (SRVResource, error) {
25492541
return SRVResource{}, &nestedError{"Port", err}
25502542
}
25512543
var target Name
2552-
if _, err := target.unpackCompressed(msg, off, false /* allowCompression */); err != nil {
2544+
if _, err := target.unpack(msg, off); err != nil {
25532545
return SRVResource{}, &nestedError{"Target", err}
25542546
}
25552547
return SRVResource{priority, weight, port, target}, nil

dns/dnsmessage/message_test.go

-22
Original file line numberDiff line numberDiff line change
@@ -303,28 +303,6 @@ func TestNameUnpackTooLongName(t *testing.T) {
303303
}
304304
}
305305

306-
func TestIncompressibleName(t *testing.T) {
307-
name := MustNewName("example.com.")
308-
compression := map[string]uint16{}
309-
buf, err := name.pack(make([]byte, 0, 100), compression, 0)
310-
if err != nil {
311-
t.Fatal("first Name.pack() =", err)
312-
}
313-
buf, err = name.pack(buf, compression, 0)
314-
if err != nil {
315-
t.Fatal("second Name.pack() =", err)
316-
}
317-
var n1 Name
318-
off, err := n1.unpackCompressed(buf, 0, false /* allowCompression */)
319-
if err != nil {
320-
t.Fatal("unpacking incompressible name without pointers failed:", err)
321-
}
322-
var n2 Name
323-
if _, err := n2.unpackCompressed(buf, off, false /* allowCompression */); err != errCompressedSRV {
324-
t.Errorf("unpacking compressed incompressible name with pointers: got %v, want = %v", err, errCompressedSRV)
325-
}
326-
}
327-
328306
func checkErrorPrefix(err error, prefix string) bool {
329307
e, ok := err.(*nestedError)
330308
return ok && e.s == prefix

0 commit comments

Comments
 (0)