]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: fix output hex encoding
authorKarel Zak <kzak@redhat.com>
Thu, 1 Aug 2019 09:43:58 +0000 (11:43 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 1 Aug 2019 09:43:58 +0000 (11:43 +0200)
The current code ignores single-byte non-printable characters.

Reported-by: Marc Deslauriers <marc.deslauriers@canonical.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c

index f0b9b7137b5e8b0996a7b2d18136c5bba7875c62..9f2e5b8042a842e828f0e29f6311e8afc15921cf 100644 (file)
@@ -637,25 +637,29 @@ static void safe_fwrite(const char *buf, size_t size, int indent, FILE *out)
                if (len == (size_t)-1 || len == (size_t)-2) {           /* invalid sequence */
                        memset(&s, 0, sizeof (s));
                        len = hex = 1;
-               } else if (len > 1 && !iswprint(wc)) {  /* non-printable multibyte */
-                       hex = 1;
-               }
-               i += len - 1;
-#else
-               len = 1;
-               if (!isprint((unsigned char) *p) &&
-                   !isspace((unsigned char) *p))        /* non-printable */
-                       hex = 1;
+                       i += len - 1;
+               } else if (len > 1) {
+                       if (!iswprint(wc) && !iswspace(wc))     /* non-printable multibyte */
+                               hex = 1;
+                       i += len - 1;
+               } else
 #endif
+               {
+                       len = 1;
+                       if (!isprint((unsigned char) *p) &&
+                           !isspace((unsigned char) *p))        /* non-printable */
+                               hex = 1;
+               }
+
                if (hex)
                        rc = fwrite_hex(p, len, out);
                else if (*p == '\n' && *(p + 1) && indent) {
                        rc = fwrite(p, 1, len, out) != len;
                        if (fprintf(out, "%*s", indent, "") != indent)
                                rc |= 1;
-               }
-               else
+               } else
                        rc = fwrite(p, 1, len, out) != len;
+
                if (rc != 0) {
                        if (errno != EPIPE)
                                err(EXIT_FAILURE, _("write failed"));