Skip to content

Commit 07a0daf

Browse files
authored
DNS: Check err for UDP dns.PackMessage(req.msg) (#5512)
Fixes #5506
1 parent 0ca1345 commit 07a0daf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/dns/nameserver_udp.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (s *ClassicNameServer) getCacheController() *CacheController {
160160
}
161161

162162
// sendQuery implements CachedNameserver.
163-
func (s *ClassicNameServer) sendQuery(ctx context.Context, _ chan<- error, fqdn string, option dns_feature.IPOption) {
163+
func (s *ClassicNameServer) sendQuery(ctx context.Context, noResponseErrCh chan<- error, fqdn string, option dns_feature.IPOption) {
164164
errors.LogInfo(ctx, s.Name(), " querying DNS for: ", fqdn)
165165

166166
reqs := buildReqMsgs(fqdn, option, s.newReqID, genEDNS0Options(s.clientIP, 0))
@@ -171,7 +171,14 @@ func (s *ClassicNameServer) sendQuery(ctx context.Context, _ chan<- error, fqdn
171171
ctx: ctx,
172172
}
173173
s.addPendingRequest(udpReq)
174-
b, _ := dns.PackMessage(req.msg)
174+
b, err := dns.PackMessage(req.msg)
175+
if err != nil {
176+
errors.LogErrorInner(ctx, err, "failed to pack dns query")
177+
if noResponseErrCh != nil {
178+
noResponseErrCh <- err
179+
}
180+
return
181+
}
175182
copyDest := net.UDPDestination(s.address.Address, s.address.Port)
176183
b.UDP = &copyDest
177184
s.udpServer.Dispatch(toDnsContext(ctx, s.address.String()), *s.address, b)

0 commit comments

Comments
 (0)