1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-03 01:17:45 +03:00

busctl: fix introspecting DBus properties

Follow-up for f2f7785d7a.

Fixes #26033.

(cherry picked from commit 2cbb171d20)
(cherry picked from commit 89e86ad8df)
(cherry picked from commit abcd25b66e)
This commit is contained in:
Yu Watanabe 2023-01-13 14:12:31 +09:00 committed by Luca Boccassi
parent 46d1581426
commit 4a0aec68da

View File

@ -1019,10 +1019,11 @@ static int introspect(int argc, char **argv, void *userdata) {
for (;;) { for (;;) {
Member *z; Member *z;
_cleanup_free_ char *buf = NULL; _cleanup_free_ char *buf = NULL, *signature = NULL;
_cleanup_fclose_ FILE *mf = NULL; _cleanup_fclose_ FILE *mf = NULL;
size_t sz = 0; size_t sz = 0;
const char *name; const char *name, *contents;
char type;
r = sd_bus_message_enter_container(reply, 'e', "sv"); r = sd_bus_message_enter_container(reply, 'e', "sv");
if (r < 0) if (r < 0)
@ -1039,6 +1040,21 @@ static int introspect(int argc, char **argv, void *userdata) {
if (r < 0) if (r < 0)
return bus_log_parse_error(r); return bus_log_parse_error(r);
r = sd_bus_message_peek_type(reply, &type, &contents);
if (r <= 0)
return bus_log_parse_error(r == 0 ? EINVAL : r);
if (type == SD_BUS_TYPE_STRUCT_BEGIN)
signature = strjoin(CHAR_TO_STR(SD_BUS_TYPE_STRUCT_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_STRUCT_END));
else if (type == SD_BUS_TYPE_DICT_ENTRY_BEGIN)
signature = strjoin(CHAR_TO_STR(SD_BUS_TYPE_DICT_ENTRY_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_DICT_ENTRY_END));
else if (contents)
signature = strjoin(CHAR_TO_STR(type), contents);
else
signature = strdup(CHAR_TO_STR(type));
if (!signature)
return log_oom();
mf = open_memstream_unlocked(&buf, &sz); mf = open_memstream_unlocked(&buf, &sz);
if (!mf) if (!mf)
return log_oom(); return log_oom();
@ -1052,6 +1068,7 @@ static int introspect(int argc, char **argv, void *userdata) {
z = set_get(members, &((Member) { z = set_get(members, &((Member) {
.type = "property", .type = "property",
.interface = m->interface, .interface = m->interface,
.signature = signature,
.name = (char*) name })); .name = (char*) name }));
if (z) if (z)
free_and_replace(z->value, buf); free_and_replace(z->value, buf);