Skip to content

Commit

Permalink
kmsg: escape the backslash character while exporting data
Browse files Browse the repository at this point in the history
Non-printable characters in the log data are hex-escaped to ensure safe
post processing. We need to escape a backslash we find in the data, to be
able to distinguish it from a backslash we add for the escaping.

Also escape the non-printable character 127.

Thanks to Miloslav Trmac for the heads up.

Reported-by: Michael Neuling <[email protected]>
Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
kaysievers authored and gregkh committed Jul 6, 2012
1 parent 5c53d81 commit e3f5a5f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
for (i = 0; i < msg->text_len; i++) {
unsigned char c = log_text(msg)[i];

if (c < ' ' || c >= 128)
if (c < ' ' || c >= 127 || c == '\\')
len += sprintf(user->buf + len, "\\x%02x", c);
else
user->buf[len++] = c;
Expand All @@ -489,7 +489,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
continue;
}

if (c < ' ' || c >= 128) {
if (c < ' ' || c >= 127 || c == '\\') {
len += sprintf(user->buf + len, "\\x%02x", c);
continue;
}
Expand Down

0 comments on commit e3f5a5f

Please sign in to comment.