summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--rfc1035label/label.go6
-rw-r--r--rfc1035label/label_test.go14
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)