]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hostnamed: port to regular string_is_safe()
authorLennart Poettering <lennart@amutable.com>
Wed, 20 May 2026 15:03:39 +0000 (17:03 +0200)
committerLennart Poettering <lennart@amutable.com>
Thu, 21 May 2026 16:30:16 +0000 (18:30 +0200)
src/hostname/hostnamed.c

index 2292c07661350f69a6a885bd6b2767e4eda87333..f8c20ff9c75a7db01f9928845d0aef797e514dbc 100644 (file)
@@ -321,18 +321,6 @@ static int context_acquire_device_tree(Context *c) {
         return 1;
 }
 
-static bool string_is_safe_for_dbus(const char *s) {
-        assert(s);
-
-        /* Do some superficial validation: do not allow CCs and make sure D-Bus won't kick us off the bus
-         * because we send invalid UTF-8 data */
-
-        if (string_has_cc(s, /* ok= */ NULL))
-                return false;
-
-        return utf8_is_valid(s);
-}
-
 static int get_dmi_property(Context *c, const char *key, char **ret) {
         const char *s;
         int r;
@@ -348,7 +336,7 @@ static int get_dmi_property(Context *c, const char *key, char **ret) {
         if (r < 0)
                 return r;
 
-        if (!string_is_safe_for_dbus(s))
+        if (!string_is_safe(s, STRING_ALLOW_EMPTY|STRING_ALLOW_BACKSLASHES|STRING_ALLOW_QUOTES|STRING_ALLOW_GLOBS))
                 return -ENXIO;
 
         return strdup_to(ret, s);
@@ -447,7 +435,7 @@ static int get_sysattr(sd_device *device, const char *key, char **ret) {
         if (r < 0)
                 return log_device_debug_errno(device, r, "Failed to read '%s' attribute: %m", key);
 
-        if (!string_is_safe_for_dbus(s))
+        if (!string_is_safe(s, STRING_ALLOW_EMPTY|STRING_ALLOW_BACKSLASHES|STRING_ALLOW_QUOTES|STRING_ALLOW_GLOBS))
                 return log_device_debug_errno(device, SYNTHETIC_ERRNO(ENXIO),
                                               "'%s' attribute is not safe for exposing through DBus: %s",
                                               key, s);