]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: do not stop on \0
authorKarel Zak <kzak@redhat.com>
Tue, 10 Sep 2019 08:34:01 +0000 (10:34 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 10 Sep 2019 08:34:01 +0000 (10:34 +0200)
... but I have doubts this change fixes the issue. It seems (on my
system) that \0 is already filtered out by kernel/syslog.

Addresses: https://github.com/karelzak/util-linux/issues/862
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c

index 55cf127f32e4341a77d7cf3cd65629230c8a5cc4..1eb7cde3c1b2bc024b682cb72876406048f72389 100644 (file)
@@ -623,6 +623,7 @@ static void safe_fwrite(struct dmesg_control *ctl, const char *buf, size_t size,
        size_t i;
 #ifdef HAVE_WIDECHAR
        mbstate_t s;
+       wchar_t wc;
        memset(&s, 0, sizeof (s));
 #endif
        for (i = 0; i < size; i++) {
@@ -631,8 +632,11 @@ static void safe_fwrite(struct dmesg_control *ctl, const char *buf, size_t size,
                size_t len = 1;
 
                if (!ctl->noesc) {
+                       if (*p == '\0') {
+                               hex = 1;
+                               goto doprint;
+                       }
 #ifdef HAVE_WIDECHAR
-                       wchar_t wc;
                        len = mbrtowc(&wc, p, size - i, &s);
 
                        if (len == 0)                           /* L'\0' */
@@ -656,6 +660,7 @@ static void safe_fwrite(struct dmesg_control *ctl, const char *buf, size_t size,
                        }
                }
 
+doprint:
                if (hex)
                        rc = fwrite_hex(p, len, out);
                else if (*p == '\n' && *(p + 1) && indent) {