util: make sure result of hostname_cleanup() passes hostname_is_valid()
This commit is contained in:
parent
ed85d9a58d
commit
cec4ead904
|
@ -3837,19 +3837,24 @@ bool hostname_is_valid(const char *s) {
|
||||||
|
|
||||||
char* hostname_cleanup(char *s) {
|
char* hostname_cleanup(char *s) {
|
||||||
char *p, *d;
|
char *p, *d;
|
||||||
|
bool dot;
|
||||||
|
|
||||||
for (p = s, d = s; *p; p++)
|
for (p = s, d = s, dot = true; *p; p++) {
|
||||||
if ((*p >= 'a' && *p <= 'z') ||
|
if (*p == '.') {
|
||||||
(*p >= 'A' && *p <= 'Z') ||
|
if (dot || p[1] == 0)
|
||||||
(*p >= '0' && *p <= '9') ||
|
continue;
|
||||||
*p == '-' ||
|
|
||||||
*p == '_' ||
|
dot = true;
|
||||||
*p == '.')
|
} else
|
||||||
|
dot = false;
|
||||||
|
|
||||||
|
if (hostname_valid_char(*p))
|
||||||
*(d++) = *p;
|
*(d++) = *p;
|
||||||
|
}
|
||||||
|
|
||||||
*d = 0;
|
*d = 0;
|
||||||
|
|
||||||
strshorten(s, HOST_NAME_MAX);
|
strshorten(s, HOST_NAME_MAX);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue