miekg / dns

DNS library in Go
https://miek.nl/2014/august/16/go-dns-package
BSD 3-Clause "New" or "Revised" License
8.09k stars 1.14k forks source link

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

Open ignoramous opened 3 weeks ago

ignoramous commented 3 weeks ago

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

https://github.com/miekg/dns/blob/b77d1ed8e9282cadf21c4124f53a660fed55c8ca/defaults.go#L147-L157

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: https://github.com/celzero/firestack/issues/111)

ignoramous commented 2 weeks ago

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 commented 5 days ago

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