@@ -1729,7 +1729,7 @@ const (
17291729//
17301730// The provided extRCode must be an extended RCode.
17311731func (h * ResourceHeader ) SetEDNS0 (udpPayloadLen int , extRCode RCode , dnssecOK bool ) error {
1732- h .Name = Name {Data : [nameLen ]byte {'.' }, Length : 1 } // RFC 6891 section 6.1.2
1732+ h .Name = Name {Data : [255 ]byte {'.' }, Length : 1 } // RFC 6891 section 6.1.2
17331733 h .Type = TypeOPT
17341734 h .Class = Class (udpPayloadLen )
17351735 h .TTL = uint32 (extRCode ) >> 4 << 24
@@ -1889,24 +1889,21 @@ func unpackBytes(msg []byte, off int, field []byte) (int, error) {
18891889 return newOff , nil
18901890}
18911891
1892- const (
1893- maxDotEncodedNameLen = 254
1894- nameLen = 255
1895- )
1892+ const nonEncodedNameMax = 254
18961893
18971894// A Name is a non-encoded domain name. It is used instead of strings to avoid
18981895// allocations.
18991896type Name struct {
1900- Data [nameLen ]byte // 255 bytes
1897+ Data [255 ]byte
19011898 Length uint8
19021899}
19031900
19041901// NewName creates a new Name from a string.
19051902func NewName (name string ) (Name , error ) {
1906- if len (name ) > nameLen {
1903+ n := Name {Length : uint8 (len (name ))}
1904+ if len (name ) > len (n .Data ) {
19071905 return Name {}, errCalcLen
19081906 }
1909- n := Name {Length : uint8 (len (name ))}
19101907 copy (n .Data [:], name )
19111908 return n , nil
19121909}
@@ -1940,7 +1937,7 @@ func (n *Name) GoString() string {
19401937func (n * Name ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
19411938 oldMsg := msg
19421939
1943- if n .Length > maxDotEncodedNameLen {
1940+ if n .Length > nonEncodedNameMax {
19441941 return nil , errNameTooLong
19451942 }
19461943
@@ -2065,7 +2062,7 @@ Loop:
20652062 if len (name ) == 0 {
20662063 name = append (name , '.' )
20672064 }
2068- if len (name ) > maxDotEncodedNameLen {
2065+ if len (name ) > nonEncodedNameMax {
20692066 return off , errNameTooLong
20702067 }
20712068 n .Length = uint8 (len (name ))
0 commit comments