Merge pull request #27611 from yuwata/core-mount-escape-utf8

core/mount: escape invalid utf8 chars
This commit is contained in:
Yu Watanabe
2023-05-12 01:40:32 +09:00
committed by GitHub
2 changed files with 61 additions and 41 deletions
+55 -12
View File
@@ -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);
+6 -29
View File
@@ -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;
r = free_and_strdup(&p->what, what);
if (r < 0)
return r;
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;
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)