hostnamed: port to regular string_is_safe()

This commit is contained in:
Lennart Poettering
2026-05-21 18:30:16 +02:00
parent 7f5503f15d
commit 5e82a8d6ee
+2 -14
View 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);