Skip to content

Commit d6d8cc1

Browse files
yuwatajamacku
authored andcommitted
core/mount: escape invalid UTF8 char in dbus reply
When What= or Options= may contain invalid UTF8 chars. Replaces aaf7b0e41105d7b7cf30912cdac32820f011a219 (#27541). (cherry picked from commit 4804da58536ab7ad46178a03f4d2da49fd8e4ba2) Resolves: RHEL-61958
1 parent fc3d25f commit d6d8cc1

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

src/core/dbus-mount.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "dbus-cgroup.h"
2828
#include "dbus-mount.h"
2929
#include "bus-util.h"
30+
#include "utf8.h"
3031

3132
static int property_get_what(
3233
sd_bus *bus,
@@ -37,21 +38,26 @@ static int property_get_what(
3738
void *userdata,
3839
sd_bus_error *error) {
3940

41+
_cleanup_free_ char *escaped = NULL;
4042
Mount *m = userdata;
41-
const char *d;
43+
const char *s = NULL;
4244

4345
assert(bus);
4446
assert(reply);
4547
assert(m);
4648

4749
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
48-
d = m->parameters_proc_self_mountinfo.what;
50+
s = m->parameters_proc_self_mountinfo.what;
4951
else if (m->from_fragment && m->parameters_fragment.what)
50-
d = m->parameters_fragment.what;
51-
else
52-
d = "";
52+
s = m->parameters_fragment.what;
53+
54+
if (s) {
55+
escaped = utf8_escape_invalid(s);
56+
if (!escaped)
57+
return -ENOMEM;
58+
}
5359

54-
return sd_bus_message_append(reply, "s", d);
60+
return sd_bus_message_append_basic(reply, 's', escaped);
5561
}
5662

5763
static int property_get_options(
@@ -63,21 +69,26 @@ static int property_get_options(
6369
void *userdata,
6470
sd_bus_error *error) {
6571

72+
_cleanup_free_ char *escaped = NULL;
6673
Mount *m = userdata;
67-
const char *d;
74+
const char *s = NULL;
6875

6976
assert(bus);
7077
assert(reply);
7178
assert(m);
7279

7380
if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
74-
d = m->parameters_proc_self_mountinfo.options;
81+
s = m->parameters_proc_self_mountinfo.options;
7582
else if (m->from_fragment && m->parameters_fragment.options)
76-
d = m->parameters_fragment.options;
77-
else
78-
d = "";
83+
s = m->parameters_fragment.options;
84+
85+
if (s) {
86+
escaped = utf8_escape_invalid(s);
87+
if (!escaped)
88+
return -ENOMEM;
89+
}
7990

80-
return sd_bus_message_append(reply, "s", d);
91+
return sd_bus_message_append_basic(reply, 's', escaped);
8192
}
8293

8394
static int property_get_type(

0 commit comments

Comments
 (0)