diff --git a/README.md b/README.md index 9110543c..41dfb71e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
- +
diff --git a/dnsutils/dns_parser.go b/dnsutils/dns_parser.go index a818a872..2148828d 100644 --- a/dnsutils/dns_parser.go +++ b/dnsutils/dns_parser.go @@ -209,6 +209,8 @@ func DecodePayload(dm *DNSMessage, header *DNSHeader, config *pkgconfig.Config) dm.DNS.Qtype = RdatatypeToString(dnsRRtype) dm.DNS.Qclass = ClassToString(dnsQclass) payloadOffset = offsetrr + } else { + payloadOffset = DNSLen } // decode DNS answers @@ -242,8 +244,9 @@ func DecodePayload(dm *DNSMessage, header *DNSHeader, config *pkgconfig.Config) return &decodingError{part: "authority records", err: err} } } + + // decode additional answers if header.Arcount > 0 { - // decode additional answers answers, _, err := DecodeAnswer(header.Arcount, payloadOffset, dm.DNS.Payload) if err == nil { // nolint dm.DNS.DNSRRs.Records = answers diff --git a/dnsutils/dns_parser_payload_test.go b/dnsutils/dns_parser_payload_test.go index d4e01a6a..e72f64e1 100644 --- a/dnsutils/dns_parser_payload_test.go +++ b/dnsutils/dns_parser_payload_test.go @@ -1042,3 +1042,47 @@ func TestDecodePayload_UpdateQuery(t *testing.T) { t.Error("expected no error on decode", err) } } + +func TestDecodePayload_MDNSResponseWithNoQuestion(t *testing.T) { + payload := []byte{ + 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x0b, 0x5f, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x63, 0x61, 0x73, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x35, 0x32, 0x53, + 0x48, 0x49, 0x45, 0x4c, 0x44, 0x2d, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2d, 0x54, 0x56, + 0x2d, 0x30, 0x66, 0x33, 0x31, 0x30, 0x63, 0x32, 0x63, 0x39, 0x66, 0x62, 0x62, 0x64, 0x61, 0x64, + 0x64, 0x31, 0x39, 0x39, 0x30, 0x30, 0x38, 0x31, 0x61, 0x61, 0x66, 0x35, 0x37, 0x65, 0x66, 0x38, + 0x33, 0xc0, 0x0c, 0xc0, 0x2e, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0xd2, 0x23, + 0x69, 0x64, 0x3d, 0x30, 0x66, 0x33, 0x31, 0x30, 0x63, 0x32, 0x63, 0x39, 0x66, 0x62, 0x62, 0x64, + 0x61, 0x64, 0x64, 0x31, 0x39, 0x39, 0x30, 0x30, 0x38, 0x31, 0x61, 0x61, 0x66, 0x35, 0x37, 0x65, + 0x66, 0x38, 0x33, 0x23, 0x63, 0x64, 0x3d, 0x42, 0x35, 0x35, 0x36, 0x39, 0x31, 0x37, 0x42, 0x30, + 0x36, 0x33, 0x38, 0x46, 0x46, 0x32, 0x43, 0x35, 0x30, 0x45, 0x42, 0x43, 0x33, 0x34, 0x34, 0x41, + 0x45, 0x35, 0x31, 0x46, 0x39, 0x43, 0x37, 0x03, 0x72, 0x6d, 0x3d, 0x05, 0x76, 0x65, 0x3d, 0x30, + 0x35, 0x14, 0x6d, 0x64, 0x3d, 0x53, 0x48, 0x49, 0x45, 0x4c, 0x44, 0x20, 0x41, 0x6e, 0x64, 0x72, + 0x6f, 0x69, 0x64, 0x20, 0x54, 0x56, 0x12, 0x69, 0x63, 0x3d, 0x2f, 0x73, 0x65, 0x74, 0x75, 0x70, + 0x2f, 0x69, 0x63, 0x6f, 0x6e, 0x2e, 0x70, 0x6e, 0x67, 0x09, 0x66, 0x6e, 0x3d, 0x53, 0x48, 0x49, + 0x45, 0x4c, 0x44, 0x09, 0x63, 0x61, 0x3d, 0x34, 0x36, 0x33, 0x33, 0x36, 0x35, 0x04, 0x73, 0x74, + 0x3d, 0x31, 0x0f, 0x62, 0x73, 0x3d, 0x46, 0x41, 0x38, 0x46, 0x46, 0x36, 0x46, 0x30, 0x45, 0x30, + 0x38, 0x38, 0x04, 0x6e, 0x66, 0x3d, 0x31, 0x09, 0x63, 0x74, 0x3d, 0x30, 0x39, 0x31, 0x43, 0x44, + 0x34, 0x13, 0x72, 0x72, 0x3d, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x4e, 0x61, 0x74, 0x69, + 0x76, 0x65, 0x41, 0x70, 0x70, 0x0b, 0x72, 0x73, 0x3d, 0x4a, 0x65, 0x6c, 0x6c, 0x79, 0x66, 0x69, + 0x6e, 0xc0, 0x2e, 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x2d, 0x00, 0x00, 0x00, + 0x00, 0x1f, 0x49, 0x24, 0x30, 0x66, 0x33, 0x31, 0x30, 0x63, 0x32, 0x63, 0x2d, 0x39, 0x66, 0x62, + 0x62, 0x2d, 0x64, 0x61, 0x64, 0x64, 0x2d, 0x31, 0x39, 0x39, 0x30, 0x2d, 0x30, 0x38, 0x31, 0x61, + 0x61, 0x66, 0x35, 0x37, 0x65, 0x66, 0x38, 0x33, 0xc0, 0x1d, 0xc1, 0x53, 0x00, 0x1c, 0x80, 0x01, + 0x00, 0x00, 0x00, 0x78, 0x00, 0x10, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x3e, + 0x51, 0x15, 0x8e, 0x6d, 0xa2, 0x96, + } + + dm := DNSMessage{} + dm.DNS.Payload = payload + dm.DNS.Length = len(payload) + + header, err := DecodeDNS(payload) + if err != nil { + t.Errorf("unexpected error when decoding header: %v", err) + } + + if err = DecodePayload(&dm, &header, pkgconfig.GetDefaultConfig()); err != nil { + t.Error("expected no error on decode", err) + } +}