Prevent logfile corruption by control codes
Do not corrupt logfiles when kernel messages contain control codes, notably \n. Instead, preserve the kernel's protective C-style hex encoding. For example, \n embedded in a message by a kernel-level facility is received as "\x0a". Kernel-level facilities cannot be trusted to use only syslog-safe codes in kernel messages. See: <https://kernel.org/doc/Documentation/ABI/testing/dev-kmsg>
This commit is contained in:
@@ -1428,18 +1428,8 @@ void printsys(char *msg)
|
||||
}
|
||||
|
||||
q = lp;
|
||||
while (*p != '\0' && (c = *p++) != '\n' && q < &line[MAXLINE]) {
|
||||
/* Linux /dev/kmsg C-style hex encoding. */
|
||||
if (c == '\\' && *p == 'x') {
|
||||
char code[5] = "0x\0\0\0";
|
||||
|
||||
p++;
|
||||
code[2] = *p++;
|
||||
code[3] = *p++;
|
||||
c = (int)strtol(code, NULL, 16);
|
||||
}
|
||||
while (*p != '\0' && (c = *p++) != '\n' && q < &line[MAXLINE])
|
||||
*q++ = c;
|
||||
}
|
||||
*q = '\0';
|
||||
|
||||
logmsg(&buffer);
|
||||
|
||||
Reference in New Issue
Block a user