summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-16 03:57:50 +0200
committerLennart Poettering <lennart@poettering.net>2013-04-16 04:41:21 +0200
commitcec4ead904978b07db2154c618eeb48d3102da66 (patch)
treee2efb971eeee82ac03885fad12fcbc0ab9e87131 /src/shared
parented85d9a58d8e404877ec4bc2f2e9d31d16b98c47 (diff)
util: make sure result of hostname_cleanup() passes hostname_is_valid()
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 5d6995d23f..4eb64934ee 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3837,19 +3837,24 @@ bool hostname_is_valid(const char *s) {
char* hostname_cleanup(char *s) {
char *p, *d;
+ bool dot;
+
+ for (p = s, d = s, dot = true; *p; p++) {
+ if (*p == '.') {
+ if (dot || p[1] == 0)
+ continue;
- for (p = s, d = s; *p; p++)
- if ((*p >= 'a' && *p <= 'z') ||
- (*p >= 'A' && *p <= 'Z') ||
- (*p >= '0' && *p <= '9') ||
- *p == '-' ||
- *p == '_' ||
- *p == '.')
+ dot = true;
+ } else
+ dot = false;
+
+ if (hostname_valid_char(*p))
*(d++) = *p;
+ }
*d = 0;
-
strshorten(s, HOST_NAME_MAX);
+
return s;
}