chiark / gitweb /
resolved: accept UTF-8 hostnames from bus clients
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Jul 2014 17:53:59 +0000 (19:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Jul 2014 17:53:59 +0000 (19:53 +0200)
src/resolve/resolved-bus.c
src/resolve/resolved-dns-domain.c

index bfb060d..6bd2b53 100644 (file)
@@ -275,7 +275,8 @@ static int bus_method_resolve_hostname(sd_bus *bus, sd_bus_message *message, voi
         if (!IN_SET(family, AF_INET, AF_INET6, AF_UNSPEC))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown address family %i", family);
 
-        if (!hostname_is_valid(hostname))
+        r = dns_name_normalize(hostname, NULL);
+        if (r < 0)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", hostname);
 
         question = dns_question_new(family == AF_UNSPEC ? 2 : 1);
@@ -566,6 +567,10 @@ static int bus_method_resolve_record(sd_bus *bus, sd_bus_message *message, void
         if (r < 0)
                 return r;
 
+        r = dns_name_normalize(name, NULL);
+        if (r < 0)
+                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid name '%s'", name);
+
         question = dns_question_new(1);
         if (!question)
                 return -ENOMEM;
index c2a4359..1bb011d 100644 (file)
@@ -172,7 +172,6 @@ int dns_name_normalize(const char *s, char **_ret) {
         int r;
 
         assert(s);
-        assert(_ret);
 
         for (;;) {
                 _cleanup_free_ char *t = NULL;
@@ -210,8 +209,11 @@ int dns_name_normalize(const char *s, char **_ret) {
                 return -ENOMEM;
 
         ret[n] = 0;
-        *_ret = ret;
-        ret = NULL;
+
+        if (_ret) {
+                *_ret = ret;
+                ret = NULL;
+        }
 
         return 0;
 }