diff --git a/CHANGELOG.md b/CHANGELOG.md index 794f1220..284fe8bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,10 +51,14 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Fixed +- Panic caused by missing user-specific blocked services object in configuration + file ([#7069]). - Tracking `/etc/hosts` file changes causing panics within particular filesystems on start ([#7076]). [#7053]: https://github.com/AdguardTeam/AdGuardHome/issues/7053 +[#7069]: https://github.com/AdguardTeam/AdGuardHome/issues/7069 +[#7076]: https://github.com/AdguardTeam/AdGuardHome/issues/7076 [install-script]: https://github.com/AdguardTeam/AdGuardHome/?tab=readme-ov-file#automated-install-linux-and-mac diff --git a/internal/client/persistent.go b/internal/client/persistent.go index 317dc72b..52f3aacc 100644 --- a/internal/client/persistent.go +++ b/internal/client/persistent.go @@ -66,7 +66,8 @@ type Persistent struct { SafeSearch filtering.SafeSearch - // BlockedServices is the configuration of blocked services of a client. + // BlockedServices is the configuration of blocked services of a client. It + // must not be nil after initialization. BlockedServices *filtering.BlockedServices Name string diff --git a/internal/home/clients.go b/internal/home/clients.go index 4f3870ec..3616cb0b 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -16,6 +16,7 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/dnsforward" "github.com/AdguardTeam/AdGuardHome/internal/filtering" "github.com/AdguardTeam/AdGuardHome/internal/querylog" + "github.com/AdguardTeam/AdGuardHome/internal/schedule" "github.com/AdguardTeam/AdGuardHome/internal/whois" "github.com/AdguardTeam/dnsproxy/proxy" "github.com/AdguardTeam/dnsproxy/upstream" @@ -261,6 +262,12 @@ func (o *clientObject) toPersistent( } } + if o.BlockedServices == nil { + o.BlockedServices = &filtering.BlockedServices{ + Schedule: schedule.EmptyWeekly(), + } + } + err = o.BlockedServices.Validate() if err != nil { return nil, fmt.Errorf("init blocked services %q: %w", cli.Name, err) diff --git a/internal/home/clientshttp.go b/internal/home/clientshttp.go index 40a91f86..fbec5c23 100644 --- a/internal/home/clientshttp.go +++ b/internal/home/clientshttp.go @@ -267,7 +267,7 @@ func copyBlockedServices( var weekly *schedule.Weekly if sch != nil { weekly = sch.Clone() - } else if prev != nil && prev.BlockedServices != nil { + } else if prev != nil { weekly = prev.BlockedServices.Schedule.Clone() } else { weekly = schedule.EmptyWeekly() diff --git a/internal/home/clientshttp_internal_test.go b/internal/home/clientshttp_internal_test.go index dc1aa87d..aa2f40fb 100644 --- a/internal/home/clientshttp_internal_test.go +++ b/internal/home/clientshttp_internal_test.go @@ -49,7 +49,7 @@ func newPersistentClient(name string) (c *client.Persistent) { Name: name, UID: client.MustNewUID(), BlockedServices: &filtering.BlockedServices{ - Schedule: &schedule.Weekly{}, + Schedule: schedule.EmptyWeekly(), }, } }