]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-daemon: escape special characters in notification logging text
authorMike Yuan <me@yhndnzj.com>
Tue, 10 Feb 2026 14:58:06 +0000 (15:58 +0100)
committerMike Yuan <me@yhndnzj.com>
Tue, 10 Feb 2026 20:53:39 +0000 (21:53 +0100)
Follow-up for 21eb636aaad28707bd371bdfd721dea66277e1f5

Our sd_notify() protocol uses newline as separator, which
is not suitable for direct logging.

src/libsystemd/sd-daemon/sd-daemon.c

index 8d7dd0823f77bf5de633ed994f152d0564930aa9..2ab50287b4ffa2cef36e55997f4ebfc7a909224f 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "alloc-util.h"
 #include "errno-util.h"
+#include "escape.h"
 #include "extract-word.h"
 #include "fd-util.h"
 #include "fs-util.h"
@@ -633,7 +634,11 @@ static int pid_notify_with_fds_internal(
                         return log_debug_errno(SYNTHETIC_ERRNO(EPROTO), "Unexpectedly received data on notify socket.");
         }
 
-        log_debug("Notify message sent to '%s': \"%s\"", e, state);
+        if (DEBUG_LOGGING) {
+                _cleanup_free_ char *escaped = xescape_full(state, "\"", /* console_width = */ SIZE_MAX, XESCAPE_8_BIT);
+                log_debug("Notify message sent to '%s': \"%s\"", e, escaped ?: state);
+        }
+
         return 1;
 }