[PATCH] Stop printk printing non-printable chars

matthew-lkml
2004-06-18T20:58:01Z

Hi,

I have had problems recently with the output from dmesg. Somewhere in
the depths of ACPI (drivers/acpi/tables.c:104) the
header->asl_compiler_id contained non-printable characters, and it made
xterm stop displaying any more output. dmesg|less had to be used as less
filters out the duff chars.

The main problem seems to be in ACPI, but I don't see any reason for
printk to even consider printing _any_ non-printable characters at all.
It makes all characters out of the range 32..126 (except for newline)
print as a '?'.

Patch is for 2.6.7.

Matthew

--- linux-2.6.7/kernel/printk.c.orig 2004-06-18 20:44:28.000000000 +0100
+++ linux-2.6.7/kernel/printk.c 2004-06-18 20:53:36.000000000 +0100
@@ -14,6 +14,8 @@
* manfreds@colorfullife.com
* Rewrote bits to get rid of console_lock
* 01Mar01 Andrew Morton <andrewm@uow.edu.au>
+ * Stop emit_log_char from emitting non-ASCII chars.
+ * Matthew Newton, 18 June 2004 <matthew-lkml@newtoncomputing.co.uk>
*/

#include <linux/kernel.h>
@@ -538,7 +540,11 @@
}
log_level_unknown = 0;
}
- emit_log_char(*p);
+ if (p[0] != '\n' && (p[0] < 32 || p[0] > 126)) {
+ emit_log_char('?');
+ } else {
+ emit_log_char(*p);
+ }
if (*p == '\n')
log_level_unknown = 1;
}