[systemd-commits] src/hostname

Lennart Poettering lennart at kemper.freedesktop.org
Tue Mar 5 12:02:13 PST 2013


 src/hostname/hostnamed.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

New commits:
commit ebe5d6d0d05d1f17c96315c42f8d9bcf5e13ba9d
Author: Nathaniel Chen <nathaniel.chen at intel.com>
Date:   Tue Mar 5 11:46:34 2013 -0800

    hostnamed: allow more special characters in pretty hostname
    
    this addresses the bug at:
      https://bugs.freedesktop.org/show_bug.cgi?id=59311
      https://bugzilla.redhat.com/show_bug.cgi?id=895299
    
    hostnamectl is supposed to allow a range of special characters for
    the 'pretty' hostname:
      $ hostnamectl set-hostname --pretty "Nathaniels Desktop !@#$%"
    ..however, it rejects apostrophes, double quotes, and backslashes.
    The manual for hostnamectl suggests that this should be allowed.
    
    It makes sense to reject \0, \n, etc. pretty_string_is_safe() is
    the same as string_is_safe(), but allows more special characters.

diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 7ea891c..979dcfd 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -159,6 +159,19 @@ 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;
@@ -553,7 +566,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 && !string_is_safe(name))
+                                if (k == PROP_PRETTY_HOSTNAME && !pretty_string_is_safe(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);



More information about the systemd-commits mailing list