From a34cf6798a303b4292760d9dbb90f5e8eba6be27 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 21 Jul 2015 07:47:38 +0100 Subject: [PATCH 1/5] Fix URI record When the URI record became an RFC they slightly changed the format. Make the needed changes. --- README.md | 10 +++++----- parse_test.go | 18 ++++++++++++++++++ types.go | 24 ++++++------------------ zscan_rr.go | 8 ++------ 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 73d62709..ec33d61c 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository. * 6975 - Algorithm Understanding in DNSSEC * 7043 - EUI48/EUI64 records * 7314 - DNS (EDNS) EXPIRE Option -* xxxx - URI record (draft) +* 7553 - URI record * xxxx - EDNS0 DNS Update Lease (draft) ## Loosely based upon @@ -138,7 +138,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository. ## TODO * privatekey.Precompute() when signing? -* Last remaining RRs: APL, ATMA, A6 and NXT and IPSECKEY; -* Missing in parsing: ISDN, UNSPEC, ATMA; -* NSEC(3) cover/match/closest enclose; -* Replies with TC bit are not parsed to the end; +* Last remaining RRs: APL, ATMA, A6 and NXT. +* Missing in parsing: ISDN, UNSPEC, ATMA. +* NSEC(3) cover/match/closest enclose. +* Replies with TC bit are not parsed to the end. diff --git a/parse_test.go b/parse_test.go index 1c2ef865..659a38ce 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1477,3 +1477,21 @@ func TestParseCAA(t *testing.T) { } } } + +func TestParseURI(t *testing.T) { + lt := map[string]string{ + "_http._tcp IN URI 10 1 \"http://www.example.com/path\"": "_http._tcp\t3600\tIN\tURI\t10 1 \"http://www.example.com/path\"", + } + for i, o := range lt { + rr, err := NewRR(i) + if err != nil { + t.Error("failed to parse RR: ", err) + continue + } + if rr.String() != o { + t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String()) + } else { + t.Logf("RR is OK: `%s'", rr.String()) + } + } +} diff --git a/types.go b/types.go index 716cabf8..34d3089b 100644 --- a/types.go +++ b/types.go @@ -503,7 +503,7 @@ func sprintName(s string) string { return string(dst) } -func sprintCAAValue(s string) string { +func sprintTxtOctet(s string) string { src := []byte(s) dst := make([]byte, 0, len(src)) dst = append(dst, '"') @@ -1329,27 +1329,15 @@ type URI struct { Hdr RR_Header Priority uint16 Weight uint16 - Target []string `dns:"txt"` + Target string `dns:"octet"` } func (rr *URI) Header() *RR_Header { return &rr.Hdr } -func (rr *URI) copy() RR { - cp := make([]string, len(rr.Target), cap(rr.Target)) - copy(cp, rr.Target) - return &URI{*rr.Hdr.copyHeader(), rr.Weight, rr.Priority, cp} -} - +func (rr *URI) copy() RR { return &URI{*rr.Hdr.copyHeader(), rr.Weight, rr.Priority, rr.Target} } +func (rr *URI) len() int { return rr.Hdr.len() + 4 + len(rr.Target) } func (rr *URI) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Priority)) + - " " + strconv.Itoa(int(rr.Weight)) + sprintTxt(rr.Target) -} - -func (rr *URI) len() int { - l := rr.Hdr.len() + 4 - for _, t := range rr.Target { - l += len(t) + 1 - } - return l + " " + strconv.Itoa(int(rr.Weight)) + sprintTxtOctet(rr.Target) } type DHCID struct { @@ -1571,7 +1559,7 @@ func (rr *CAA) Header() *RR_Header { return &rr.Hdr } func (rr *CAA) copy() RR { return &CAA{*rr.Hdr.copyHeader(), rr.Flag, rr.Tag, rr.Value} } func (rr *CAA) len() int { return rr.Hdr.len() + 1 + len(rr.Tag) + len(rr.Value)/2 } func (rr *CAA) String() string { - return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintCAAValue(rr.Value) + return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintTxtOctet(rr.Value) } type UID struct { diff --git a/zscan_rr.go b/zscan_rr.go index 3763d3f4..c8d73afc 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -1876,9 +1876,6 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Hdr = h l := <-c - if l.length == 0 { - return rr, nil, l.comment - } i, e := strconv.Atoi(l.token) if e != nil { return nil, &ParseError{f, "bad URI Priority", l}, "" @@ -1897,7 +1894,7 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if e != nil { return nil, e.(*ParseError), "" } - rr.Target = s + rr.Target = s[0] return rr, nil, c1 } @@ -2197,9 +2194,8 @@ func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } if len(s) > 1 { return nil, &ParseError{f, "bad CAA Value", l}, "" - } else { - rr.Value = s[0] } + rr.Value = s[0] return rr, nil, c1 } From 179a68fbec278aa00311019507dea1aca4259eeb Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 27 Jul 2015 22:12:46 +0100 Subject: [PATCH 2/5] Some small fixes --- parse_test.go | 2 +- types.go | 2 +- zscan_rr.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/parse_test.go b/parse_test.go index 659a38ce..b20abb10 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1480,7 +1480,7 @@ func TestParseCAA(t *testing.T) { func TestParseURI(t *testing.T) { lt := map[string]string{ - "_http._tcp IN URI 10 1 \"http://www.example.com/path\"": "_http._tcp\t3600\tIN\tURI\t10 1 \"http://www.example.com/path\"", + "_http._tcp. IN URI 10 1 \"http://www.example.com/path\"": "_http._tcp.\t3600\tIN\tURI\t10 1 \"http://www.example.com/path\"", } for i, o := range lt { rr, err := NewRR(i) diff --git a/types.go b/types.go index 34d3089b..a60e423a 100644 --- a/types.go +++ b/types.go @@ -1337,7 +1337,7 @@ func (rr *URI) copy() RR { return &URI{*rr.Hdr.copyHeader(), rr.Weight func (rr *URI) len() int { return rr.Hdr.len() + 4 + len(rr.Target) } func (rr *URI) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Priority)) + - " " + strconv.Itoa(int(rr.Weight)) + sprintTxtOctet(rr.Target) + " " + strconv.Itoa(int(rr.Weight)) + " " + sprintTxtOctet(rr.Target) } type DHCID struct { diff --git a/zscan_rr.go b/zscan_rr.go index c8d73afc..dbfdba13 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -1890,9 +1890,9 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Weight = uint16(i) <-c // zBlank - s, e, c1 := endingToTxtSlice(c, "bad URI Target", f) - if e != nil { - return nil, e.(*ParseError), "" + s, err, c1 := endingToTxtSlice(c, "bad URI Target", f) + if err != nil { + return nil, err, "" } rr.Target = s[0] return rr, nil, c1 @@ -2180,7 +2180,7 @@ func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { } rr.Flag = uint8(i) - <-c // zBlank + <-c // zBlank l = <-c // zString if l.value != zString { return nil, &ParseError{f, "bad CAA Tag", l}, "" From b26019349afb788c8b6fde2f36d3dc48728fdf96 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 27 Jul 2015 22:22:18 +0100 Subject: [PATCH 3/5] make dynamic updates work for URI --- zscan_rr.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zscan_rr.go b/zscan_rr.go index dbfdba13..14e881c9 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -1876,6 +1876,10 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { rr.Hdr = h l := <-c + if l.length == 0 { // Dynamic updates. + return rr, nil, "" + } + i, e := strconv.Atoi(l.token) if e != nil { return nil, &ParseError{f, "bad URI Priority", l}, "" From 9d8cd1bfd92422b846831e1d6942bd83da551b3d Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 28 Jul 2015 07:20:54 +0100 Subject: [PATCH 4/5] Test parsing empty target --- parse_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/parse_test.go b/parse_test.go index b20abb10..46790023 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1481,6 +1481,7 @@ func TestParseCAA(t *testing.T) { func TestParseURI(t *testing.T) { lt := map[string]string{ "_http._tcp. IN URI 10 1 \"http://www.example.com/path\"": "_http._tcp.\t3600\tIN\tURI\t10 1 \"http://www.example.com/path\"", + "_http._tcp. IN URI 10 1 \"\"": "_http._tcp.\t3600\tIN\tURI\t10 1 \"\"", } for i, o := range lt { rr, err := NewRR(i) From 3085a49d25adcd2702eca750867107c1975efcfe Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 28 Jul 2015 21:44:50 +0100 Subject: [PATCH 5/5] disallow multiple uri fragments --- zscan_rr.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zscan_rr.go b/zscan_rr.go index 14e881c9..03e78db5 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -1898,6 +1898,9 @@ func setURI(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { if err != nil { return nil, err, "" } + if len(s) > 1 { + return nil, &ParseError{f, "bad URI Target", l}, "" + } rr.Target = s[0] return rr, nil, c1 }