From ef57f7e192fdd4fbbfe25dc1c1e61d52e9f0b6ee Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Thu, 12 Dec 2019 15:04:29 +0300 Subject: [PATCH] - DNS: fix race in WriteDiskConfig() --- dnsforward/dnsforward.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dnsforward/dnsforward.go b/dnsforward/dnsforward.go index f5963058..8027bc5b 100644 --- a/dnsforward/dnsforward.go +++ b/dnsforward/dnsforward.go @@ -86,10 +86,23 @@ func (s *Server) Close() { s.Unlock() } +func stringArrayDup(a []string) []string { + a2 := make([]string, len(a)) + copy(a2, a) + return a2 +} + // WriteDiskConfig - write configuration func (s *Server) WriteDiskConfig(c *FilteringConfig) { s.Lock() - *c = s.conf.FilteringConfig + sc := s.conf.FilteringConfig + *c = sc + c.RatelimitWhitelist = stringArrayDup(sc.RatelimitWhitelist) + c.BootstrapDNS = stringArrayDup(sc.BootstrapDNS) + c.AllowedClients = stringArrayDup(sc.AllowedClients) + c.DisallowedClients = stringArrayDup(sc.DisallowedClients) + c.BlockedHosts = stringArrayDup(sc.BlockedHosts) + c.UpstreamDNS = stringArrayDup(sc.UpstreamDNS) s.Unlock() }