From: Lennart Poettering Date: Mon, 22 Apr 2024 10:32:54 +0000 (+0200) Subject: resolved: tighten the rules a bit on valid DNS-SD service identifiers X-Git-Tag: v256-rc1~71^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c903d3df6ff848c5f1c1e8a4aaaaa3d2d219c339;p=thirdparty%2Fsystemd.git resolved: tighten the rules a bit on valid DNS-SD service identifiers Let's insist that the ID is suitable for inclusion in a filename, as one of the most basic of requirements. --- diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c index 080a4beccef..d6d2273dc9d 100644 --- a/src/resolve/resolved-bus.c +++ b/src/resolve/resolved-bus.c @@ -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();