Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net/dns/dnsmessage: missing validation of current section for cached headers #62220

Closed
neild opened this issue Aug 22, 2023 · 1 comment
Closed
Assignees
Milestone

Comments

@neild
Copy link
Contributor

neild commented Aug 22, 2023

Parser.resourceHeader and Parser.skipResource don't check that the section being parsed/skipped matches the current section when p.resHeaderValid is set:
https://go.googlesource.com/net/+/refs/tags/v0.14.0/dns/dnsmessage/message.go#597
https://go.googlesource.com/net/+/refs/tags/v0.14.0/dns/dnsmessage/message.go#615

In short:

p.SkipAllQuestions()
h, err := p.AnswerHeader() // parse first Answer
h, err = p.AnswerHeader() // return first Answer again, parser has not advanced to the next record
h, err = p.AuthorityHeader() // return first Answer, even though we're asking for an Authority

In more detail, this test fails on the last t.Fatalf:

  func TestSkipEach(t *testing.T) {
          msg := Message{
                  Header: Header{Response: true, Authoritative: true},
                  Answers: []Resource{
                          {
                                  ResourceHeader{
                                          Name:  MustNewName("answer.example.com."),
                                          Type:  TypeA,
                                          Class: ClassINET,
                                  },
                                  &AResource{[4]byte{127, 0, 0, 1}},
                          },
                  },
                  Authorities: []Resource{
                          {
                                  ResourceHeader{
                                          Name:  MustNewName("authority.example.com."),
                                          Type:  TypeNS,
                                          Class: ClassINET,
                                  },
                                  &NSResource{MustNewName("ns1.example.com.")},
                          },
                  },
          }

          buf, err := msg.Pack()
          if err != nil {
                  t.Fatal("Message.Pack() =", err)
          }
          var p Parser
          if _, err := p.Start(buf); err != nil {
                  t.Fatal("Parser.Start(non-nil) =", err)
          }

          p.SkipAllQuestions()
          h, err := p.AuthorityHeader()
          if err == nil {
                  t.Fatalf("in Answer section: p.AuthorityHeader() = %q, nil, want error", h.Name.String())
          }
          h, err = p.AnswerHeader()
          if err != nil {
                  t.Fatalf("in Answer section: p.AnswerHeader() = _, %v, want nil", err)
          }
          if got, want := h.Name.String(), "answer.example.com."; got != want {
                  t.Fatalf("Answer name = %q, want %q", got, want)
          }
          h, err = p.AuthorityHeader()
          if err == nil {
                  t.Fatalf("in Answer section: p.AuthorityHeader() = %q, nil, want error", h.Name.String())
          }
  }
--- FAIL: TestSkipEach (0.00s)
    message_test.go:545: in Answer section: p.AuthorityHeader() = "answer.example.com.", nil, want error
@gopherbot gopherbot added this to the Unreleased milestone Aug 22, 2023
@neild neild self-assigned this Aug 22, 2023
@gopherbot
Copy link

Change https://go.dev/cl/521995 mentions this issue: dns/dnsmessage: validate cached section when skipping sections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants