mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-08-16 22:20:30 +03:00
Pull request: 2582 invalid hostname
Merge in DNS/adguard-home from 2582-invalid-hostname to master Updates #2582. Squashed commit of the following: commit 909598dae00588792b092f89c272c4487ba55dd1 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Mar 4 17:32:58 2021 +0300 all: imp code quality, log changes commit b3b970803709030c48cfe343b88d73524a043de3 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Mar 4 16:56:28 2021 +0300 home: add host processing logic
This commit is contained in:
parent
400b76d47b
commit
90ebc4d8c9
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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]))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user