[systemd-commits] 2 commits - src/hostname src/shared src/test
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Mar 22 10:01:50 PDT 2013
src/hostname/hostnamed.c | 15 +--------------
src/shared/util.c | 20 +++++++++++++++++---
src/test/test-util.c | 14 ++++++++++++++
3 files changed, 32 insertions(+), 17 deletions(-)
New commits:
commit 737732a41e5702540f51c760bebd3b8152c04727
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Mar 22 18:01:26 2013 +0100
hostnamed: pretty_string_is_safe() already exists in string_has_cc(), so use that
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 25e154b..859b5a0 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -159,19 +159,6 @@ static bool valid_chassis(const char *chassis) {
chassis);
}
-static bool pretty_string_is_safe(const char *p) {
- const char *t;
-
- assert(p);
-
- for (t = p; *t; t++) {
- if (*t >= '\0' && *t < ' ')
- return false;
- }
-
- return true;
-}
-
static const char* fallback_chassis(void) {
int r;
char *type;
@@ -566,7 +553,7 @@ static DBusHandlerResult hostname_message_handler(
* safe than sorry */
if (k == PROP_ICON_NAME && !filename_is_safe(name))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
- if (k == PROP_PRETTY_HOSTNAME && !pretty_string_is_safe(name))
+ if (k == PROP_PRETTY_HOSTNAME && string_has_cc(name))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
if (k == PROP_CHASSIS && !valid_chassis(name))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
commit aa3c5cf8eefa36a3ae727fe136587381e590d333
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Mar 22 17:59:49 2013 +0100
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
diff --git a/src/shared/util.c b/src/shared/util.c
index 020b75d..bc6e035 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;
diff --git a/src/test/test-util.c b/src/test/test-util.c
index cd017ef..08310c8 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -325,6 +325,19 @@ static void test_bus_path_escape(void) {
test_bus_path_escape_one(":1", "_3a1");
}
+static void test_hostname_is_valid(void) {
+ assert(hostname_is_valid("foobar"));
+ assert(hostname_is_valid("foobar.com"));
+ assert(!hostname_is_valid("fööbar"));
+ assert(!hostname_is_valid(""));
+ assert(!hostname_is_valid("."));
+ assert(!hostname_is_valid(".."));
+ assert(!hostname_is_valid("foobar."));
+ assert(!hostname_is_valid(".foobar"));
+ assert(!hostname_is_valid("foo..bar"));
+ assert(!hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
+}
+
int main(int argc, char *argv[]) {
test_streq_ptr();
test_first_word();
@@ -349,6 +362,7 @@ int main(int argc, char *argv[]) {
test_default_term_for_tty();
test_memdup_multiply();
test_bus_path_escape();
+ test_hostname_is_valid();
return 0;
}
More information about the systemd-commits
mailing list