summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2019-08-01 11:43:58 +0200
committerKarel Zak2019-08-01 11:43:58 +0200
commit3661aab4cf7509b03f749477082553f4eee7dc0e (patch)
tree5604330fdaa4fedce3f30ed33b987ae5b105741e
parentchoom: improve docs (diff)
downloadkernel-qcow2-util-linux-3661aab4cf7509b03f749477082553f4eee7dc0e.tar.gz
kernel-qcow2-util-linux-3661aab4cf7509b03f749477082553f4eee7dc0e.tar.xz
kernel-qcow2-util-linux-3661aab4cf7509b03f749477082553f4eee7dc0e.zip
dmesg: fix output hex encoding
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>
-rw-r--r--sys-utils/dmesg.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index f0b9b7137..9f2e5b804 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -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"));