]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysupdate: generalize feature name validity check
authorLennart Poettering <lennart@amutable.com>
Fri, 10 Jul 2026 12:34:59 +0000 (14:34 +0200)
committerLennart Poettering <lennart@amutable.com>
Fri, 10 Jul 2026 12:37:17 +0000 (14:37 +0200)
Let's switch to string_is_safe(), and make this available to the rest of
the sysupdate sources too.

This both relaxes and tighten the rules slightly. i.e. control character
and stuff are no longer allowed, but valid UTF-8 (as opposed to ASCII)
now is.

src/sysupdate/meson.build
src/sysupdate/sysupdate-util.c
src/sysupdate/sysupdate-util.h
src/sysupdate/sysupdated.c

index 664f439f797e936fa00e6a5ce629a50531d3624a..c4f569096f9c251fa500b135dc9a17368bf9dee3 100644 (file)
@@ -39,7 +39,7 @@ executables += [
                 'name' : 'systemd-sysupdated',
                 'dbus' : true,
                 'conditions' : ['ENABLE_SYSUPDATED'],
-                'sources' : files('sysupdated.c', 'sysupdate-target.c'),
+                'sources' : files('sysupdated.c', 'sysupdate-target.c', 'sysupdate-util.c'),
         },
         executable_template + {
                 'name' : 'updatectl',
index 8b0a4924e4cd6168f2d6f522c5c6d3c575322028..579c107154965e19e7400637227f6a51dfc78884 100644 (file)
@@ -31,6 +31,17 @@ int reboot_now(void) {
         return 0;
 }
 
+bool feature_name_valid(const char *c) {
+
+        if (!string_is_safe(c, STRING_FILENAME_PART))
+                return false;
+
+        /* Stack allocation is safe, since STRING_FILENAME_PART includes a length check */
+        const char *j = strjoina(c, ".feature.d");
+
+        return filename_is_valid(j);
+}
+
 bool component_name_valid(const char *c) {
         /* See if the specified string enclosed in the directory prefix+suffix would be a valid file name */
 
index 07d9def70872e58fe7dc97809a56e9f00343b49b..6d5230f1e3312b64333ec265a6cb2565d7f0edd0 100644 (file)
@@ -8,5 +8,7 @@ int reboot_now(void);
 #define SD_SYSUPDATE_OFFLINE   (UINT64_C(1) << 0)
 #define SD_SYSUPDATE_FLAGS_ALL (SD_SYSUPDATE_OFFLINE)
 
+bool feature_name_valid(const char *c);
+
 bool component_name_valid(const char *c);
 int get_component_list(const char *root, char ***ret);
index 8022fde77eb6ff075669a7ddc2e840f9414f1ffc..bc5a2439b5a3e939645e385cd4fee0caaa0dbf0e 100644 (file)
@@ -32,7 +32,6 @@
 #include "notify-recv.h"
 #include "os-util.h"
 #include "parse-util.h"
-#include "path-util.h"
 #include "pidref.h"
 #include "process-util.h"
 #include "runtime-scope.h"
@@ -42,7 +41,6 @@
 #include "strv.h"
 #include "sysupdate-target.h"
 #include "sysupdate-util.h"
-#include "utf8.h"
 
 #define FEATURES_DROPIN_NAME "systemd-sysupdate-enabled"
 
@@ -1404,19 +1402,6 @@ static int target_method_list_features(sd_bus_message *msg, void *userdata, sd_b
         return sd_bus_message_send(reply);
 }
 
-static bool feature_name_is_valid(const char *name) {
-        if (isempty(name))
-                return false;
-
-        if (!ascii_is_valid(name))
-                return false;
-
-        if (!filename_is_valid(strjoina(name, ".feature.d")))
-                return false;
-
-        return true;
-}
-
 static int target_method_describe_feature(sd_bus_message *msg, void *userdata, sd_bus_error *error) {
         Target *t = ASSERT_PTR(userdata);
         _cleanup_(job_freep) Job *j = NULL;
@@ -1430,7 +1415,7 @@ static int target_method_describe_feature(sd_bus_message *msg, void *userdata, s
         if (r < 0)
                 return r;
 
-        if (!feature_name_is_valid(feature))
+        if (!feature_name_valid(feature))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid feature name");
 
         if (flags != 0)
@@ -1470,7 +1455,7 @@ static int target_method_set_feature_enabled(sd_bus_message *msg, void *userdata
         r = sd_bus_message_read(msg, "sit", &feature, &enabled, &flags);
         if (r < 0)
                 return r;
-        if (!feature_name_is_valid(feature))
+        if (!feature_name_valid(feature))
                 return sd_bus_reply_method_errorf(msg,
                                                   SD_BUS_ERROR_INVALID_ARGS,
                                                   "The specified feature is invalid");