diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-05-12 01:40:32 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-12 01:40:32 +0900 |
commit | db4afb95c278af41c715a1c62813de3072e28cea (patch) | |
tree | a17d5bce55181c7c0593743271102f843cf62bd8 /src | |
parent | b0582f6b635011506fdf68d0afdc128ab10f6c6a (diff) | |
parent | 4804da58536ab7ad46178a03f4d2da49fd8e4ba2 (diff) | |
download | systemd-db4afb95c278af41c715a1c62813de3072e28cea.tar.gz |
Merge pull request #27611 from yuwata/core-mount-escape-utf8
core/mount: escape invalid utf8 chars
Diffstat (limited to 'src')
-rw-r--r-- | src/core/dbus-mount.c | 67 | ||||
-rw-r--r-- | src/core/mount.c | 35 |
2 files changed, 61 insertions, 41 deletions
diff --git a/src/core/dbus-mount.c b/src/core/dbus-mount.c index 73702b1a16..55ad4f2c98 100644 --- a/src/core/dbus-mount.c +++ b/src/core/dbus-mount.c @@ -9,21 +9,66 @@ #include "mount.h" #include "string-util.h" #include "unit.h" +#include "utf8.h" + +static int property_get_what( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + _cleanup_free_ char *escaped = NULL; + Mount *m = ASSERT_PTR(userdata); + const char *s = NULL; + + assert(bus); + assert(reply); -static const char *mount_get_what(const Mount *m) { if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what) - return m->parameters_proc_self_mountinfo.what; - if (m->from_fragment && m->parameters_fragment.what) - return m->parameters_fragment.what; - return NULL; + s = m->parameters_proc_self_mountinfo.what; + else if (m->from_fragment && m->parameters_fragment.what) + s = m->parameters_fragment.what; + + if (s) { + escaped = utf8_escape_invalid(s); + if (!escaped) + return -ENOMEM; + } + + return sd_bus_message_append_basic(reply, 's', escaped); } -static const char *mount_get_options(const Mount *m) { +static int property_get_options( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + _cleanup_free_ char *escaped = NULL; + Mount *m = ASSERT_PTR(userdata); + const char *s = NULL; + + assert(bus); + assert(reply); + if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options) - return m->parameters_proc_self_mountinfo.options; - if (m->from_fragment && m->parameters_fragment.options) - return m->parameters_fragment.options; - return NULL; + s = m->parameters_proc_self_mountinfo.options; + else if (m->from_fragment && m->parameters_fragment.options) + s = m->parameters_fragment.options; + + if (s) { + escaped = utf8_escape_invalid(s); + if (!escaped) + return -ENOMEM; + } + + return sd_bus_message_append_basic(reply, 's', escaped); } static const char *mount_get_fstype(const Mount *m) { @@ -34,8 +79,6 @@ static const char *mount_get_fstype(const Mount *m) { return NULL; } -static BUS_DEFINE_PROPERTY_GET(property_get_what, "s", Mount, mount_get_what); -static BUS_DEFINE_PROPERTY_GET(property_get_options, "s", Mount, mount_get_options); static BUS_DEFINE_PROPERTY_GET(property_get_type, "s", Mount, mount_get_fstype); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult); diff --git a/src/core/mount.c b/src/core/mount.c index b87b57b7ad..549d7dbf98 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -34,7 +34,6 @@ #include "strv.h" #include "unit-name.h" #include "unit.h" -#include "utf8.h" #define RETRY_UMOUNT_MAX 32 @@ -275,35 +274,13 @@ static int update_parameters_proc_self_mountinfo( p = &m->parameters_proc_self_mountinfo; - if (what && !utf8_is_valid(what)) { - _cleanup_free_ char *what_escaped = NULL; - - what_escaped = utf8_escape_invalid(what); - if (!what_escaped) - return -ENOMEM; - - r = !streq_ptr(p->what, what_escaped); - free_and_replace(p->what, what_escaped); - } else { - r = free_and_strdup(&p->what, what); - if (r < 0) - return r; - } - - if (options && !utf8_is_valid(options)) { - _cleanup_free_ char *options_escaped = NULL; - - options_escaped = utf8_escape_invalid(options); - if (!options_escaped) - return -ENOMEM; + r = free_and_strdup(&p->what, what); + if (r < 0) + return r; - q = !streq_ptr(p->options, options_escaped); - free_and_replace(p->options, options_escaped); - } else { - q = free_and_strdup(&p->options, options); - if (q < 0) - return q; - } + q = free_and_strdup(&p->options, options); + if (q < 0) + return q; w = free_and_strdup(&p->fstype, fstype); if (w < 0) |