From 3f3c1d6d78c2e77b2bf21c38fc476f93156470e1 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 6 Jul 2023 23:42:04 +0700 Subject: [PATCH] Fix Ping upstream cause ctrld crash dohTransport returns a http.RoundTripper. When pinging upstream, we do it both for doh and doh3, and checking whether the transport is nil before performing the check. However, dohTransport returns a concrete *http.Transport. Thus dohTransport will always return a non-nil http.Roundtripper, causing invalid memory dereference when upstream is configured to use doh3. Performing ping upstream separately will fix the issue. --- config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index cb51e97..9c553b2 100644 --- a/config.go +++ b/config.go @@ -407,8 +407,12 @@ func (uc *UpstreamConfig) Ping() { } for _, typ := range []uint16{dns.TypeA, dns.TypeAAAA} { - ping(uc.dohTransport(typ)) - ping(uc.doh3Transport(typ)) + switch uc.Type { + case ResolverTypeDOH: + ping(uc.dohTransport(typ)) + case ResolverTypeDOH3: + ping(uc.doh3Transport(typ)) + } } }