sysupdate: generalize feature name validity check

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.
This commit is contained in:
Lennart Poettering
2026-07-10 14:37:17 +02:00
parent 058cbd2aba
commit d298f9bc8e
4 changed files with 16 additions and 18 deletions
+1 -1
View 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',
+11
View 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 */
+2
View 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);
+2 -17
View 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");