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

nil ptr in defaults.go:152 msg.IsEdns0 #1614

Open
ignoramous opened this issue Nov 3, 2024 · 2 comments
Open

nil ptr in defaults.go:152 msg.IsEdns0 #1614

ignoramous opened this issue Nov 3, 2024 · 2 comments

Comments

@ignoramous
Copy link

ignoramous commented Nov 3, 2024

A crash report from our app points to a nil ptr whilst iterating over Extra RRs:

dns/defaults.go

Lines 147 to 157 in b77d1ed

func (dns *Msg) IsEdns0() *OPT {
// RFC 6891, Section 6.1.1 allows the OPT record to appear
// anywhere in the additional record section, but it's usually at
// the end so start there.
for i := len(dns.Extra) - 1; i >= 0; i-- {
if dns.Extra[i].Header().Rrtype == TypeOPT {
return dns.Extra[i].(*OPT)
}
}
return nil
}

11-03 05:50:57.349 32129 20730 E LibLogger: panic({0x763892d0c0?, 0x7638f537d0?})
11-03 05:50:57.349 32129 20730 E LibLogger:     /home/jitpack/golang/go/src/runtime/panic.go:785 +0x124
11-03 05:50:57.349 32129 20730 E LibLogger: github.com/miekg/dns.(*Msg).IsEdns0(0x40008b9710)
11-03 05:50:57.349 32129 20730 E LibLogger:     /tmp/gomobile-work-1841608193/pkg/mod/github.com/miekg/dns@v1.1.62/defaults.go:152 +0x60
11-03 05:50:57.349 32129 20730 E LibLogger: github.com/celzero/firestack/intra/xdns.ensureEDNS0(0x40008b9710)
11-03 05:50:57.349 32129 20730 E LibLogger:     /home/jitpack/build/intra/xdns/dnsutil.go:480 +0x20
11-03 05:50:57.349 32129 20730 E LibLogger: github.com/celzero/firestack/intra/xdns.AddEDNS0PaddingIfNoneFound(0x40008b9710)
11-03 05:50:57.349 32129 20730 E LibLogger:     /home/jitpack/build/intra/xdns/dnsutil.go:517 +0x24
11-03 05:50:57.349 32129 20730 E LibLogger: github.com/celzero/firestack/intra/doh.padQuery(0x40008b9710)
11-03 05:50:57.349 32129 20730 E LibLogger:     /home/jitpack/build/intra/doh/padding.go:35 +0x40
11-03 05:50:57.349 32129 20730 E LibLogger: github.com/celzero/firestack/intra/doh.(*transport).doDoh(0x40003dc160, {0x4000f84bdc, 0x4}, 0x40008b9710)
11-03 05:50:57.349 32129 20730 E LibLogger:     /home/jitpack/build/intra/doh/doh.go:372 +0x44
11-03 05:50:57.349 32129 20730 E LibLogger: github.com/celzero/firestack/intra/doh.(*transport).Query(0x40003dc160, {0x4000f84bd8, 0x8}, 0x40008b9710, 0x4000ec2600)
11-03 05:50:57.349 32129 20730 E LibLogger:     /home/jitpack/build/intra/doh/doh.go:679 +0xa8
11-03 05:50:57.349 32129 20730 E LibLogger: github.com/celzero/firestack/intra/dnsx.Req({0x7638a462f0, 0x40003dc160}, {0x4000f84bd8, 0x8}, 0x40008b9710, 0x4000ec2600)
11-03 05:50:57.349 32129 20730 E LibLogger:     /home/jitpack/build/intra/dnsx/alg.go:1129 +0x12c

Unsure if it is incorrect use of the lib by our code, or something that's indicative of other issues (as I see miekg/dns codebase accessing struct fields ex: Extra[x].Header() all too often).

(from: celzero/firestack#111)

@ignoramous ignoramous changed the title nil ptr in defaults.go:52 msg.IsEdns0 nil ptr in defaults.go:152 msg.IsEdns0 Nov 3, 2024
@ignoramous
Copy link
Author

If it helps, managed to grab a str(query) from a recent crash log:

;; opcode: QUERY, status: NOERROR, id: 0
;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version 0; flags:; udp: 4096
; PADDING: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

;; QUESTION SECTION:
;github.com.	IN	 HTTPS

@miekg
Copy link
Owner

miekg commented Nov 22, 2024

thanks for that. This indeed needs a fix. Maybe I have the cycles this weekend

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