summaryrefslogtreecommitdiffhomepage
path: root/rfc1035label
diff options
context:
space:
mode:
authorErik Geiser <erik.geiser@redteam-pentesting.de>2022-05-23 14:38:45 +0200
committerErik Geiser <erik.geiser@redteam-pentesting.de>2022-05-23 14:38:45 +0200
commita91ce0db92a593b386863adceaf420b01f5de1a3 (patch)
treee6cde5056223edae2add6c25daf70cc67194a6ba /rfc1035label
parentb437b69f18fd2a2e59bd3ff51685896ee53d0709 (diff)
Decode partial domain name labels
Signed-off-by: Erik Geiser <erik.geiser@redteam-pentesting.de>
Diffstat (limited to 'rfc1035label')
-rw-r--r--rfc1035label/label.go8
-rw-r--r--rfc1035label/label_test.go4
2 files changed, 11 insertions, 1 deletions
diff --git a/rfc1035label/label.go b/rfc1035label/label.go
index 5a67d7c..561008e 100644
--- a/rfc1035label/label.go
+++ b/rfc1035label/label.go
@@ -100,6 +100,14 @@ 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)
+
+ return labels, nil
+ }
+
break
}
length := int(buf[pos])
diff --git a/rfc1035label/label_test.go b/rfc1035label/label_test.go
index 2e20736..865b41a 100644
--- a/rfc1035label/label_test.go
+++ b/rfc1035label/label_test.go
@@ -28,7 +28,9 @@ func TestLabelsFromBytesZeroLength(t *testing.T) {
require.Equal(t, []byte{}, labels.ToBytes())
}
-func TestLabelsFromBytesWithoutZeroLength(t *testing.T) {
+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',
}