From cb19b08dac6c486f64e0577bc4c0fd92e0ea4552 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 13 Jul 2015 10:19:34 -0700 Subject: [PATCH] logd: refine is_prio (cherry pick from commit 618d0dec5037df0fad1ce5cc90da2b7fc2c88b0c) - Heuristics associated with translation of kernel messages to Android user space logs. - Limit is_prio to 4 characters, we got false positives on hex values like with no alpha chars. - x11 and other register definitions are not valid tags, en0 is - fix some Android coding standard issues Change-Id: Idc3dcc53a2cb75ac38628c8ef7a5d5b53f12587a --- logd/LogKlog.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp index d578c04db..d3a73a189 100644 --- a/logd/LogKlog.cpp +++ b/logd/LogKlog.cpp @@ -43,8 +43,10 @@ static char *is_prio(char *s) { if (!isdigit(*s++)) { return NULL; } + static const size_t max_prio_len = 4; + size_t len = 0; char c; - while ((c = *s++)) { + while (((c = *s++)) && (++len <= max_prio_len)) { if (!isdigit(c)) { return (c == '>') ? s : NULL; } @@ -73,7 +75,7 @@ static char *is_timestamp(char *s) { } // Like strtok_r with "\r\n" except that we look for log signatures (regex) -// \(\(<[0-9]+>\)\([[] *[0-9]+[.][0-9]+[]] \)\{0,1\}\|[[] *[0-9]+[.][0-9]+[]] \) +// \(\(<[0-9]\{1,4\}>\)\([[] *[0-9]+[.][0-9]+[]] \)\{0,1\}\|[[] *[0-9]+[.][0-9]+[]] \) // and split if we see a second one without a newline. #define SIGNATURE_MASK 0xF0 @@ -165,7 +167,7 @@ char *log_strtok_r(char *s, char **last) { break; } } - /* NOTREACHED */ + // NOTREACHED } log_time LogKlog::correction = log_time(CLOCK_REALTIME) - log_time(CLOCK_MONOTONIC); @@ -465,7 +467,7 @@ int LogKlog::log(const char *buf) { if (strncmp(bt, cp, size)) { // [