]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tighten the rules a bit on valid DNS-SD service identifiers
authorLennart Poettering <lennart@poettering.net>
Mon, 22 Apr 2024 10:32:54 +0000 (12:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 22 Apr 2024 13:16:54 +0000 (15:16 +0200)
Let's insist that the ID is suitable for inclusion in a filename, as one
of the most basic of requirements.

src/resolve/resolved-bus.c

index 080a4beccef4ccacc8f805d1f2280c802020705d..d6d2273dc9dc56f82ca387e2c4ed3d3e48653e2f 100644 (file)
@@ -11,6 +11,7 @@
 #include "format-util.h"
 #include "memory-util.h"
 #include "missing_capability.h"
+#include "path-util.h"
 #include "resolved-bus.h"
 #include "resolved-def.h"
 #include "resolved-dns-stream.h"
@@ -1898,13 +1899,16 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
         if (r < 0)
                 return r;
 
-        s = hashmap_get(m->dnssd_services, id);
-        if (s)
-                return sd_bus_error_setf(error, BUS_ERROR_DNSSD_SERVICE_EXISTS, "DNS-SD service '%s' exists already", id);
+        if (!filename_part_is_valid(id))
+                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DNS-SD service identifier '%s' is invalid", id);
 
         if (!dnssd_srv_type_is_valid(type))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DNS-SD service type '%s' is invalid", type);
 
+        s = hashmap_get(m->dnssd_services, id);
+        if (s)
+                return sd_bus_error_setf(error, BUS_ERROR_DNSSD_SERVICE_EXISTS, "DNS-SD service '%s' exists already", id);
+
         service->id = strdup(id);
         if (!service->id)
                 return log_oom();