Attached.

I also noticed a minor C correctness problem in print_multiline(): if
the last line of message has no newline, then end = message+message_len.
The next loop iteration calculates "pos = end + 1". This means that pos
points 2 past the last byte, which is not guaranteed to be a valid
address calculation for general C objects (could theoretically wrap
around to start of address space etc). Probably won't be called with
such objects in practice.

>From 4775218f59474165395f7868dfbf9e6b831f5fee Mon Sep 17 00:00:00 2001
From: Uoti Urpala <uau@glyph.nonexistent.invalid>
Date: Thu, 20 Feb 2014 02:31:04 +0200
Subject: [PATCH] logs-show: fix corrupt output with empty messages

If a message had zero length, journalctl would print no newline, and
two output lines would be concatenated. Fix. The problem was
introduced in commit 31f7bf199452 ("logs-show: print multiline
messages"). Affected short and verbose output modes.

Before fix:

Feb 09 21:16:17 glyph dhclient[1323]: Feb 09 21:16:17 glyph NetworkManager[788]: <info> (enp4s2): DHCPv4 state changed nbi -> preinit

after:

Feb 09 21:16:17 glyph dhclient[1323]:
Feb 09 21:16:17 glyph NetworkManager[788]: <info> (enp4s2): DHCPv4 state changed nbi -> preinit
---
 src/shared/logs-show.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 0f27c4e..fb2aeda 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -124,6 +124,13 @@ static bool print_multiline(FILE *f, unsigned prefix, unsigned n_columns, Output
                 }
         }
 
+        if (message_len == 0) {
+                /* Without this, the loop below would print no '\n' for empty
+                 * message. */
+                message = "\n";
+                message_len = 1;
+        }
+
         for (pos = message;
              pos < message + message_len;
              pos = end + 1, line++) {
-- 
1.7.6.561.g3822

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to