Skip to content

Commit

Permalink
Set Rdlength in fromRFC3597
Browse files Browse the repository at this point in the history
This was a bug found by oss-fuzz. My bad (miekg#1211).
  • Loading branch information
tmthrgd committed Jan 31, 2021
1 parent ba2d042 commit 5df9283
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ func (rr *RFC3597) ToRFC3597(r RR) error {

// fromRFC3597 converts an unknown RR representation from RFC 3597 to the known RR type.
func (rr *RFC3597) fromRFC3597(r RR) error {
*r.Header() = rr.Hdr
hdr := r.Header()
*hdr = rr.Hdr
hdr.Rdlength = uint16(len(rr.Rdata) / 2)

if len(rr.Rdata) == 0 {
if noRdata(*hdr) {
// Dynamic update.
return nil
}
Expand Down
10 changes: 8 additions & 2 deletions scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ example.com. 60 PX (

func TestParseKnownRRAsRFC3597(t *testing.T) {
t.Run("with RDATA", func(t *testing.T) {
// This was found by oss-fuzz.
_, err := NewRR("example. 3600 tYpe44 \\# 03 75 0100")
if err != nil {
t.Errorf("failed to parse RFC3579 format: %v", err)
}

rr, err := NewRR("example. 3600 CLASS1 TYPE1 \\# 4 7f000001")
if err != nil {
t.Fatalf("failed to parse RFC3579 format: %v", err)
Expand All @@ -247,7 +253,7 @@ func TestParseKnownRRAsRFC3597(t *testing.T) {

localhost := net.IPv4(127, 0, 0, 1)
if !a.A.Equal(localhost) {
t.Fatalf("expected A with IP %v, but got %v", localhost, a.A)
t.Errorf("expected A with IP %v, but got %v", localhost, a.A)
}
})
t.Run("without RDATA", func(t *testing.T) {
Expand All @@ -266,7 +272,7 @@ func TestParseKnownRRAsRFC3597(t *testing.T) {
}

if len(a.A) != 0 {
t.Fatalf("expected A with empty IP, but got %v", a.A)
t.Errorf("expected A with empty IP, but got %v", a.A)
}
})
}
Expand Down

0 comments on commit 5df9283

Please sign in to comment.