From ddb842ac9342438aae65f8aaf8ce66fb41ca65a1 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 10 Nov 2015 15:56:41 -0800 Subject: [PATCH] logd: klogd: parse error (cherry pick from commit eb298086153a9502bb0b02a1a26919a482b52535) Resolve three areas missing taglen checking. Add some additional limit-checking paranoia. Problem started when p was allowed to go beyond the size of the incoming buffer in some blind p = cp + 1 fragments, placed the check for that after them all before harm could be done, rather than in each location. Bug: 25620123 Change-Id: Ib5687fd30ef0cd3ba3bc0df310b436ad675ccabc --- logd/LogKlog.cpp | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp index da5e78d66..2a3f52f99 100644 --- a/logd/LogKlog.cpp +++ b/logd/LogKlog.cpp @@ -582,7 +582,7 @@ int LogKlog::log(const char *buf, size_t len) { // Some may view the following as an ugly heuristic, the desire is to // beautify the kernel logs into an Android Logging format; the goal is // admirable but costly. - while ((isspace(*p) || !*p) && (p < &buf[len])) { + while ((p < &buf[len]) && (isspace(*p) || !*p)) { ++p; } if (p >= &buf[len]) { // timestamp, no content @@ -596,7 +596,7 @@ int LogKlog::log(const char *buf, size_t len) { const char *bt, *et, *cp; bt = p; - if (!fast(p, "[INFO]", 6)) { + if ((taglen >= 6) && !fast(p, "[INFO]", 6)) { // [