X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fbus-util.c;fp=src%2Fshared%2Fbus-util.c;h=485bd0885a2492b3c5bfe0cbbdf91531b6ba87e8;hp=c2465ea55de7e134a89ac5ba09ac8a7e6d57017a;hb=460285493762467d6657e52f243d923907d19b8d;hpb=4c98c6b0da003b18b24bab98099b4449ff475097 diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index c2465ea55..485bd0885 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -728,8 +728,14 @@ int bus_print_property(const char *name, sd_bus_message *property, bool value, b if (r < 0) return r; - if (all || !isempty(s)) - print_property(name, "%s", s); + if (all || !isempty(s)) { + bool good; + + /* This property has a single value, so we need to take + * care not to print a new line, everything else is OK. */ + good = !strchr(s, '\n'); + print_property(name, "%s", good ? s : "[unprintable]"); + } return 1; } @@ -849,10 +855,16 @@ int bus_print_property(const char *name, sd_bus_message *property, bool value, b return r; while ((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) > 0) { + bool good; + if (first && !value) printf("%s=", name); - printf("%s%s", first ? "" : " ", str); + /* This property has multiple space-seperated values, so + * neither spaces not newlines can be allowed in a value. */ + good = str[strcspn(str, " \n")] == '\0'; + + printf("%s%s", first ? "" : " ", good ? str : "[unprintable]"); first = false; }