summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-22 17:59:49 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-22 17:59:49 +0100
commitaa3c5cf8eefa36a3ae727fe136587381e590d333 (patch)
treeacbed0a1fb454bd7e89d9539aa70ab0012274cc4 /src/shared/util.c
parent4468addca6d01a0d2d154371dd72f54307a9c786 (diff)
util: be more picky when validating hostnames
No longer allow dots at the beginning or end of host names, Or double dots. https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1152187/comments/14
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 020b75d0f2..bc6e035c60 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3773,13 +3773,27 @@ static bool hostname_valid_char(char c) {
bool hostname_is_valid(const char *s) {
const char *p;
+ bool dot;
if (isempty(s))
return false;
- for (p = s; *p; p++)
- if (!hostname_valid_char(*p))
- return false;
+ for (p = s, dot = true; *p; p++) {
+ if (*p == '.') {
+ if (dot)
+ return false;
+
+ dot = true;
+ } else {
+ if (!hostname_valid_char(*p))
+ return false;
+
+ dot = false;
+ }
+ }
+
+ if (dot)
+ return false;
if (p-s > HOST_NAME_MAX)
return false;