Skip to content

Commit 4eca25e

Browse files
authored
Merge pull request #1680 from pi-hole/fix/gravity_dash_dot
Fix regression of #1667
2 parents 4c6dadd + 2bd4e6b commit 4eca25e

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/tools/gravity-parseList.c

+13-21
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,8 @@ static inline bool __attribute__((pure)) valid_domain(const char *domain, const
4747
if(domain == NULL || len == 0 || len > 255)
4848
return false;
4949

50-
// Domain must not start or end with a hyphen or dot
51-
if(domain[ 0 ] == '-' || domain[ 0 ] == '.' ||
52-
domain[len-1] == '-' || domain[len-1] == '.')
53-
return false;
54-
5550
// Loop over line and check for invalid characters
56-
unsigned int last_dot = 0;
51+
int last_dot = -1;
5752
for(unsigned int i = 0; i < len; i++)
5853
{
5954
// Domain must not contain any character other than [a-zA-Z0-9.-_]
@@ -63,23 +58,14 @@ static inline bool __attribute__((pure)) valid_domain(const char *domain, const
6358
(domain[i] < '0' || domain[i] > '9'))
6459
return false;
6560

66-
// Multi-character checks
67-
if(i > 0)
68-
{
69-
// Domain must not contain a hyphen immediately before a
70-
// dot or two consecutive dots
71-
if(domain[i] == '.' && (domain[i-1] == '-' || domain[i-1] == '.'))
72-
return false;
73-
74-
// Domain must not contain a dot immediately before a
75-
// hyphen
76-
if(domain[i] == '-' && domain[i-1] == '.')
77-
return false;
78-
}
79-
8061
// Individual label length check
8162
if(domain[i] == '.')
8263
{
64+
// Label must be longer than 0 characters, i.e., two consecutive
65+
// dots are not allowed
66+
if(i - last_dot == 1)
67+
return false;
68+
8369
// Label must not be longer than 63 characters
8470
// (actually 64 because the dot at the end of the label
8571
// is included here)
@@ -95,9 +81,15 @@ static inline bool __attribute__((pure)) valid_domain(const char *domain, const
9581
}
9682
}
9783

84+
// TLD checks
85+
9886
// There must be at least two labels (i.e. one dot)
9987
// e.g., "example.com" but not "localhost"
100-
if(last_dot == 0)
88+
if(last_dot == -1)
89+
return false;
90+
91+
// TLD must not start or end with a hyphen
92+
if(domain[last_dot + 1] == '-' || domain[len - 1] == '-')
10193
return false;
10294

10395
// TLD length check

0 commit comments

Comments
 (0)