From: Yu Watanabe Date: Sat, 26 Jul 2025 18:55:16 +0000 (+0900) Subject: sd-bus: escape invalid characters in error message X-Git-Tag: v258-rc2~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31f388ea15b09c410882051e482f1145366e4940;p=thirdparty%2Fsystemd.git sd-bus: escape invalid characters in error message At many places, we pass arguments of dbus method calls to sd_bus_error_setf(), and produces unprintable log messages. Let's always escape the generated error message. This fixes something like the following: ``` [ 1921.875668] systemd-logind[611]: Got message type=method_call sender=:1.46 destination=:1.6 path=/org/freedesktop/login1 interface=org.freedesktop.login1.Manager member=GetSeat cookie=1344 reply_cookie=0 signature=s error-name=n/a error-message=n/a [ 1921.875758] systemd-logind[611]: [725B blob data] [ 1921.875777] systemd-logind[611]: [768B blob data] ``` --- diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c index b61df06632d..cf501c33c9f 100644 --- a/src/libsystemd/sd-bus/bus-error.c +++ b/src/libsystemd/sd-bus/bus-error.c @@ -7,6 +7,7 @@ #include "errno-list.h" #include "errno-util.h" #include "string-util.h" +#include "utf8.h" BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_standard_errors[] = { SD_BUS_ERROR_MAP(SD_BUS_ERROR_FAILED, EACCES), @@ -246,7 +247,7 @@ _public_ int sd_bus_error_setfv(sd_bus_error *e, const char *name, const char *f * this, since we at least managed to write the error name */ if (vasprintf(&mesg, format, ap) >= 0) - e->message = TAKE_PTR(mesg); + e->message = utf8_escape_non_printable(mesg); } e->_need_free = 1;