Skip to content

Commit 8af6615

Browse files
committed
config: reject hostnames whose last label is too long
`valid_domain()` measured a label when it found the terminating dot, so the last one was never checked and `1.2.3.4 test.<64 characters>` passed. dnsmasq rejects labels above 63 characters, so with `dns.hostsLocal` such an entry produced a `local=` line that makes the resolver refuse to start. Signed-off-by: DL6ER <dl6er@dl6er.de>
1 parent a787629 commit 8af6615

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/tools/gravity-parseList.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ inline bool __attribute__((pure)) valid_domain(const char *domain, const size_t
9898

9999
// TLD checks
100100

101+
// The last label is not followed by a dot, so the loop above never
102+
// checked its length
103+
if(len - (size_t)(last_dot + 1) > 63)
104+
return false;
105+
101106
// There must be at least two labels (i.e. one dot)
102107
// e.g., "example.com" but not "localhost" for exact domain
103108
// We do not enforce this for ABP domains and domainlist input

test/test_suite.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,12 @@ setup() {
16301630
assert_line --index 0 'Invalid value: dns.hosts[2]: entry does not have at least one hostname ("1.2.3.4")'
16311631
assert_failure 3
16321632

1633+
# The final label is subject to the 63 character limit as well
1634+
long_label="$(printf 'a%.0s' {1..64})"
1635+
run bash -c "./pihole-FTL --config dns.hosts '[\"1.2.3.4 test.${long_label}\"]'"
1636+
assert_line --index 0 "Invalid value: dns.hosts[0]: invalid hostname (\"test.${long_label}\")"
1637+
assert_failure 3
1638+
16331639
run bash -c './pihole-FTL --config dns.revServers "[\"abc,def,ghi\"]"'
16341640
assert_line --index 0 'Invalid value: dns.revServers[0]: <enabled> not a boolean ("abc")'
16351641
assert_failure 3

0 commit comments

Comments
 (0)