]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: escape UTF-8 in mount unit Where field before sending to clients
authorLennart Poettering <lennart@poettering.net>
Fri, 20 Jun 2025 11:16:10 +0000 (13:16 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 20 Jun 2025 17:22:28 +0000 (02:22 +0900)
Followup for: 4804da58536ab7ad46178a03f4d2da49fd8e4ba2 #27541

Fixes: #36206
src/core/dbus-mount.c
src/core/mount.c
src/core/mount.h
test/units/TEST-07-PID1.mount-invalid-chars.sh

index 6c10e476b9c336d6c2ad18aebe90d1f5d6606145..50fa339fb4fb64b59758d6df6200494e5b1f416b 100644 (file)
 #include "string-util.h"
 #include "unit.h"
 
+static int property_get_where(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        Mount *m = ASSERT_PTR(userdata);
+
+        assert(bus);
+        assert(reply);
+
+        _cleanup_free_ char *escaped = mount_get_where_escaped(m);
+        if (!escaped)
+                return -ENOMEM;
+
+        return sd_bus_message_append_basic(reply, 's', escaped);
+}
+
 static int property_get_what(
                 sd_bus *bus,
                 const char *path,
@@ -60,7 +81,7 @@ static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResu
 
 const sd_bus_vtable bus_mount_vtable[] = {
         SD_BUS_VTABLE_START(0),
-        SD_BUS_PROPERTY("Where", "s", NULL, offsetof(Mount, where), SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("Where", "s", property_get_where, 0, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("What", "s", property_get_what, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("Type", "s", property_get_type, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
index aa6a41fc0f1e1315f7bb76a8f46c8cf86670ee43..7e9e23d6fd6200dc710f8241e6b8a0484f9f14c8 100644 (file)
@@ -636,7 +636,11 @@ static int mount_add_extras(Mount *m) {
         path_simplify(m->where);
 
         if (!u->description) {
-                r = unit_set_description(u, m->where);
+                _cleanup_free_ char *w = mount_get_where_escaped(m);
+                if (!w)
+                        return log_oom();
+
+                r = unit_set_description(u, w);
                 if (r < 0)
                         return r;
         }
@@ -2390,6 +2394,15 @@ static int mount_subsystem_ratelimited(Manager *m) {
         return sd_event_source_is_ratelimited(m->mount_event_source);
 }
 
+char* mount_get_where_escaped(const Mount *m) {
+        assert(m);
+
+        if (!m->where)
+                return strdup("");
+
+        return utf8_escape_invalid(m->where);
+}
+
 char* mount_get_what_escaped(const Mount *m) {
         _cleanup_free_ char *escaped = NULL;
         const char *s = NULL;
index 9aaef8dd39101ede5a43131c49c3d84e981f7d2b..d9f8d4f663b782dc73bdf83821f23d73914edf7e 100644 (file)
@@ -94,6 +94,7 @@ extern const UnitVTable mount_vtable;
 
 void mount_fd_event(Manager *m, int events);
 
+char* mount_get_where_escaped(const Mount *m);
 char* mount_get_what_escaped(const Mount *m);
 char* mount_get_options_escaped(const Mount *m);
 const char* mount_get_fstype(const Mount *m);
index a87933486961e540134960dae069f0c738f99a1a..cd2ca78fdfc41d9adc47d96b0cec0268fadee621 100755 (executable)
@@ -23,12 +23,13 @@ TMP_MOUNTINFO="$(mktemp)"
 
 cp /proc/1/mountinfo "$TMP_MOUNTINFO"
 # Add a mount entry with a "Unicode non-character" in it
-LANG="C.UTF-8" printf '69 1 252:2 / /foo/mountinfo rw,relatime shared:1 - cifs //foo\ufffebar rw,seclabel\n' >>"$TMP_MOUNTINFO"
+LANG="C.UTF-8" printf '69 1 252:2 / /foo/mount\ufffeinfo rw,relatime shared:1 - cifs //foo\ufffebar rw,seclabel\n' >>"$TMP_MOUNTINFO"
 mount --bind "$TMP_MOUNTINFO" /proc/1/mountinfo
 systemctl daemon-reload
 # On affected versions this would throw an error:
 #   Failed to get properties: Bad message
-systemctl status foo-mountinfo.mount
+systemctl list-units -t mount
+systemctl status foo-mount\\xef\\xbf\\xbeinfo.mount
 
 umount /proc/1/mountinfo
 systemctl daemon-reload