diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2022-09-15 23:58:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-15 23:58:10 +0100 |
commit | 043f1726f02e2908b959423a0b95a9affdc08b73 (patch) | |
tree | fd8e8b029c4d0fe417855b6f775abba2e6f6e42d | |
parent | 3194d6dcbf023c0bab49842c67de204ad416e7e9 (diff) | |
parent | 034ec2b821e6f661b6635d46f2f05931b284cc02 (diff) |
Merge pull request #467 from rtpt-erikgeiser/fix_label
Add Support for Labels Containing Partial Domain Names (RFC 4704 Section 4.2)
-rw-r--r-- | rfc1035label/label.go | 6 | ||||
-rw-r--r-- | rfc1035label/label_test.go | 14 |
2 files changed, 20 insertions, 0 deletions
diff --git a/rfc1035label/label.go b/rfc1035label/label.go index 5a67d7c..042c17b 100644 --- a/rfc1035label/label.go +++ b/rfc1035label/label.go @@ -100,6 +100,12 @@ func labelsFromBytes(buf []byte) ([]string, error) { for { if pos >= len(buf) { + // interpret label without trailing zero-length byte as a partial + // domain name field as per RFC 4704 Section 4.2 + if label != "" { + labels = append(labels, label) + } + break } length := int(buf[pos]) diff --git a/rfc1035label/label_test.go b/rfc1035label/label_test.go index 6098e44..865b41a 100644 --- a/rfc1035label/label_test.go +++ b/rfc1035label/label_test.go @@ -28,6 +28,20 @@ func TestLabelsFromBytesZeroLength(t *testing.T) { require.Equal(t, []byte{}, labels.ToBytes()) } +func TestLabelsFromBytesPartialDomainName(t *testing.T) { + // Partial domain name without trailing zero-length byte as per RFC 4704 + // Section 4.2 + expected := []byte{ + 0x8, 'h', 'o', 's', 't', 'n', 'a', 'm', 'e', + } + labels, err := FromBytes(expected) + require.NoError(t, err) + require.Equal(t, 1, len(labels.Labels)) + require.Equal(t, len(expected), labels.Length()) + require.Equal(t, expected, labels.ToBytes()) + require.Equal(t, "hostname", labels.Labels[0]) +} + func TestLabelsFromBytesInvalidLength(t *testing.T) { _, err := FromBytes([]byte{0x5, 0xaa, 0xbb}) // short length require.Error(t, err) |