diff --git a/CHANGELOG.md b/CHANGELOG.md index 12b8d1a7..a409cd8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to ### Fixed +- Incomplete hostnames with trailing zero-bytes handling ([#2582]). - Wrong DNS-over-TLS ALPN configuration ([#2681]). - Inconsistent responses for messages with EDNS0 and AD when DNS caching is enabled ([#2600]). @@ -27,6 +28,7 @@ and this project adheres to - Incomplete DNS upstreams validation ([#2674]). - Wrong parsing of DHCP options of the `ip` type ([#2688]). +[#2582]: https://github.com/AdguardTeam/AdGuardHome/issues/2582 [#2600]: https://github.com/AdguardTeam/AdGuardHome/issues/2600 [#2674]: https://github.com/AdguardTeam/AdGuardHome/issues/2674 [#2681]: https://github.com/AdguardTeam/AdGuardHome/issues/2681 diff --git a/internal/home/clients.go b/internal/home/clients.go index 5a9e9eac..6c314874 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -586,9 +586,22 @@ func (clients *clientsContainer) SetWhoisInfo(ip string, info [][]string) { log.Debug("clients: set whois info for auto-client with IP %s: %q", ip, info) } +// sanitizeHost proccesses a host to remove some special symbols causing errors. +// Logic may be expanded in the future. +func sanitizeHost(host string) (processed string) { + // cutset brings together all the deprecated sets. + // + // See https://github.com/AdguardTeam/AdGuardHome/issues/2582. + const cutset = "\x00" + + return strings.TrimRight(host, cutset) +} + // AddHost adds a new IP-hostname pairing. The priorities of the sources is // taken into account. ok is true if the pairing was added. func (clients *clientsContainer) AddHost(ip, host string, src clientSource) (ok bool, err error) { + host = sanitizeHost(host) + clients.lock.Lock() ok = clients.addHostLocked(ip, host, src) clients.lock.Unlock() diff --git a/internal/home/clients_test.go b/internal/home/clients_test.go index a098bf4c..e6200ddd 100644 --- a/internal/home/clients_test.go +++ b/internal/home/clients_test.go @@ -290,3 +290,29 @@ func TestClientsCustomUpstream(t *testing.T) { assert.Equal(t, 1, len(config.Upstreams)) assert.Equal(t, 1, len(config.DomainReservedUpstreams)) } + +func TestProcessHost(t *testing.T) { + const ( + name int = iota + host + want + + fieldsNum + ) + + testCases := [][fieldsNum]string{{ + name: "valid", + host: "abc", + want: "abc", + }, { + name: "with_trailing_zero_byte", + host: "abc\x00", + want: "abc", + }} + + for _, tc := range testCases { + t.Run(tc[name], func(t *testing.T) { + assert.Equal(t, tc[want], sanitizeHost(tc[host])) + }) + } +}