From b82ad3720cbb3cfba98bbeae9f483134793dfe0f Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 19 Dec 2023 01:44:23 +0700 Subject: [PATCH] cmd/cli: guard against nil client info Though it's only possible raised in testing, still better to be safe. --- cmd/cli/dns_proxy.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/cli/dns_proxy.go b/cmd/cli/dns_proxy.go index 7d1f9e3..fc319f2 100644 --- a/cmd/cli/dns_proxy.go +++ b/cmd/cli/dns_proxy.go @@ -504,7 +504,11 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *dns.Msg { p.cache.Add(dnscache.NewKey(req.msg, upstreams[n]), dnscache.NewValue(answer, expired)) ctrld.Log(ctx, mainLog.Load().Debug(), "add cached response") } - ctrld.Log(ctx, mainLog.Load().Info(), "REPLY: %s -> %s (%s): %s", upstreams[n], req.ufr.srcAddr, req.ci.Hostname, dns.RcodeToString[answer.Rcode]) + hostname := "" + if req.ci != nil { + hostname = req.ci.Hostname + } + ctrld.Log(ctx, mainLog.Load().Info(), "REPLY: %s -> %s (%s): %s", upstreams[n], req.ufr.srcAddr, hostname, dns.RcodeToString[answer.Rcode]) return answer } ctrld.Log(ctx, mainLog.Load().Error(), "all %v endpoints failed", upstreams)