From 27032ef79e3013f439b11c2d22c1dba9bde0c858 Mon Sep 17 00:00:00 2001
From: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Mon, 3 Oct 2022 17:30:03 +0300
Subject: [PATCH] home: fix empty svcs

---
 internal/home/clients.go |  4 ----
 internal/home/dns.go     | 12 +++++++++---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/internal/home/clients.go b/internal/home/clients.go
index 61802831..7396e8c6 100644
--- a/internal/home/clients.go
+++ b/internal/home/clients.go
@@ -244,10 +244,6 @@ func (clients *clientsContainer) addFromConfig(objects []*clientObject) {
 			}
 		}
 
-		if cli.BlockedServices == nil && cli.UseOwnBlockedServices {
-			cli.BlockedServices = []string{}
-		}
-
 		for _, t := range o.Tags {
 			if clients.allTags.Has(t) {
 				cli.Tags = append(cli.Tags, t)
diff --git a/internal/home/dns.go b/internal/home/dns.go
index c533807e..79901c27 100644
--- a/internal/home/dns.go
+++ b/internal/home/dns.go
@@ -335,6 +335,8 @@ func applyAdditionalFiltering(clientIP net.IP, clientID string, setts *filtering
 	// pref is a prefix for logging messages around the scope.
 	const pref = "applying filters"
 
+	Context.filters.ApplyBlockedServices(setts, nil)
+
 	log.Debug("%s: looking for client with ip %s and clientid %q", pref, clientIP, clientID)
 
 	if clientIP == nil {
@@ -356,9 +358,13 @@ func applyAdditionalFiltering(clientIP net.IP, clientID string, setts *filtering
 	log.Debug("%s: using settings for client %q (%s; %q)", pref, c.Name, clientIP, clientID)
 
 	if c.UseOwnBlockedServices {
-		Context.filters.ApplyBlockedServices(setts, c.BlockedServices)
-	} else {
-		Context.filters.ApplyBlockedServices(setts, nil)
+		// TODO(e.burkov):  Get rid of this crutch.
+		svcs := c.BlockedServices
+		if svcs == nil {
+			svcs = []string{}
+		}
+		Context.filters.ApplyBlockedServices(setts, svcs)
+		log.Debug("services set: %v", setts.ServicesRules)
 	}
 
 	setts.ClientName = c.Name