From 2e588677716f3e7f84c6274aeeb943efd6b96770 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Tue, 3 Jan 2017 10:35:34 -0800 Subject: [PATCH] LogAudit.cpp: replace newlines with spaces in audit messages Some kernels have a bug which causes a newline to show up in audit messages. The embedded newlines cause one message to look like two due to prefix controls. Replace any newlines with spaces. Duplicate spaces are further consolidated in code immediately after this newly added code. Test: create an audit message with a newline, and watch it be cleaned up. Bug: 27878170 Change-Id: Id90c29ab9e10d3be96f51403b0293622d782422a --- logd/LogAudit.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp index aa05932b0..6f29ead54 100644 --- a/logd/LogAudit.cpp +++ b/logd/LogAudit.cpp @@ -94,6 +94,13 @@ int LogAudit::logPrint(const char *fmt, ...) { } char *cp; + // Work around kernels missing + // https://github.com/torvalds/linux/commit/b8f89caafeb55fba75b74bea25adc4e4cd91be67 + // Such kernels improperly add newlines inside audit messages. + while ((cp = strchr(str, '\n'))) { + *cp = ' '; + } + while ((cp = strstr(str, " "))) { memmove(cp, cp + 1, strlen(cp + 1) + 1); }