|
91 | 91 | errTooManyAdditionals = errors.New("too many Additionals to pack (>65535)")
|
92 | 92 | errNonCanonicalName = errors.New("name is not in canonical format (it must end with a .)")
|
93 | 93 | errStringTooLong = errors.New("character string exceeds maximum length (255)")
|
| 94 | + errCompressedSRV = errors.New("compressed name in SRV resource data") |
94 | 95 | )
|
95 | 96 |
|
96 | 97 | // Internal constants.
|
@@ -1610,6 +1611,10 @@ func (n *Name) pack(msg []byte, compression map[string]int, compressionOff int)
|
1610 | 1611 |
|
1611 | 1612 | // unpack unpacks a domain name.
|
1612 | 1613 | func (n *Name) unpack(msg []byte, off int) (int, error) {
|
| 1614 | + return n.unpackCompressed(msg, off, true /* allowCompression */) |
| 1615 | +} |
| 1616 | + |
| 1617 | +func (n *Name) unpackCompressed(msg []byte, off int, allowCompression bool) (int, error) { |
1613 | 1618 | // currOff is the current working offset.
|
1614 | 1619 | currOff := off
|
1615 | 1620 |
|
@@ -1645,6 +1650,9 @@ Loop:
|
1645 | 1650 | name = append(name, '.')
|
1646 | 1651 | currOff = endOff
|
1647 | 1652 | case 0xC0: // Pointer
|
| 1653 | + if !allowCompression { |
| 1654 | + return off, errCompressedSRV |
| 1655 | + } |
1648 | 1656 | if currOff >= len(msg) {
|
1649 | 1657 | return off, errInvalidPtr
|
1650 | 1658 | }
|
@@ -2044,7 +2052,7 @@ func unpackSRVResource(msg []byte, off int) (SRVResource, error) {
|
2044 | 2052 | return SRVResource{}, &nestedError{"Port", err}
|
2045 | 2053 | }
|
2046 | 2054 | var target Name
|
2047 |
| - if _, err := target.unpack(msg, off); err != nil { |
| 2055 | + if _, err := target.unpackCompressed(msg, off, false /* allowCompression */); err != nil { |
2048 | 2056 | return SRVResource{}, &nestedError{"Target", err}
|
2049 | 2057 | }
|
2050 | 2058 | return SRVResource{priority, weight, port, target}, nil
|
|
0 commit comments