Merge "logd: klogd: parse error"
am: c6f3b96bd8
* commit 'c6f3b96bd8b9b0ca366009db6b6e497761adb642':
logd: klogd: parse error
This commit is contained in:
commit
c7017ffbc8
1 changed files with 27 additions and 11 deletions
|
|
@ -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
|
// 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
|
// beautify the kernel logs into an Android Logging format; the goal is
|
||||||
// admirable but costly.
|
// admirable but costly.
|
||||||
while ((isspace(*p) || !*p) && (p < &buf[len])) {
|
while ((p < &buf[len]) && (isspace(*p) || !*p)) {
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
if (p >= &buf[len]) { // timestamp, no content
|
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;
|
const char *bt, *et, *cp;
|
||||||
|
|
||||||
bt = p;
|
bt = p;
|
||||||
if (!fast<strncmp>(p, "[INFO]", 6)) {
|
if ((taglen >= 6) && !fast<strncmp>(p, "[INFO]", 6)) {
|
||||||
// <PRI>[<TIME>] "[INFO]"<tag> ":" message
|
// <PRI>[<TIME>] "[INFO]"<tag> ":" message
|
||||||
bt = p + 6;
|
bt = p + 6;
|
||||||
taglen -= 6;
|
taglen -= 6;
|
||||||
|
|
@ -620,7 +620,9 @@ int LogKlog::log(const char *buf, size_t len) {
|
||||||
p = cp + 1;
|
p = cp + 1;
|
||||||
} else if (taglen) {
|
} else if (taglen) {
|
||||||
size = et - bt;
|
size = et - bt;
|
||||||
if ((*bt == *cp) && fast<strncmp>(bt + 1, cp + 1, size - 1)) {
|
if ((taglen > size) && // enough space for match plus trailing :
|
||||||
|
(*bt == *cp) && // ubber fast<strncmp> pair
|
||||||
|
fast<strncmp>(bt + 1, cp + 1, size - 1)) {
|
||||||
// <PRI>[<TIME>] <tag>_host '<tag>.<num>' : message
|
// <PRI>[<TIME>] <tag>_host '<tag>.<num>' : message
|
||||||
if (!fast<strncmp>(bt + size - 5, "_host", 5)
|
if (!fast<strncmp>(bt + size - 5, "_host", 5)
|
||||||
&& !fast<strncmp>(bt + 1, cp + 1, size - 6)) {
|
&& !fast<strncmp>(bt + 1, cp + 1, size - 6)) {
|
||||||
|
|
@ -694,7 +696,7 @@ int LogKlog::log(const char *buf, size_t len) {
|
||||||
p = cp + 1;
|
p = cp + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} /* else no tag */
|
||||||
size = etag - tag;
|
size = etag - tag;
|
||||||
if ((size <= 1)
|
if ((size <= 1)
|
||||||
// register names like x9
|
// register names like x9
|
||||||
|
|
@ -721,8 +723,12 @@ int LogKlog::log(const char *buf, size_t len) {
|
||||||
taglen = mp - tag;
|
taglen = mp - tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Deal with sloppy and simplistic harmless p = cp + 1 etc above.
|
||||||
|
if (len < (size_t)(p - buf)) {
|
||||||
|
p = &buf[len];
|
||||||
|
}
|
||||||
// skip leading space
|
// skip leading space
|
||||||
while ((isspace(*p) || !*p) && (p < &buf[len])) {
|
while ((p < &buf[len]) && (isspace(*p) || !*p)) {
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
// truncate trailing space or nuls
|
// truncate trailing space or nuls
|
||||||
|
|
@ -735,16 +741,26 @@ int LogKlog::log(const char *buf, size_t len) {
|
||||||
p = " ";
|
p = " ";
|
||||||
b = 1;
|
b = 1;
|
||||||
}
|
}
|
||||||
|
// paranoid sanity check, can not happen ...
|
||||||
if (b > LOGGER_ENTRY_MAX_PAYLOAD) {
|
if (b > LOGGER_ENTRY_MAX_PAYLOAD) {
|
||||||
b = LOGGER_ENTRY_MAX_PAYLOAD;
|
b = LOGGER_ENTRY_MAX_PAYLOAD;
|
||||||
}
|
}
|
||||||
|
if (taglen > LOGGER_ENTRY_MAX_PAYLOAD) {
|
||||||
|
taglen = LOGGER_ENTRY_MAX_PAYLOAD;
|
||||||
|
}
|
||||||
|
// calculate buffer copy requirements
|
||||||
size_t n = 1 + taglen + 1 + b + 1;
|
size_t n = 1 + taglen + 1 + b + 1;
|
||||||
int rc = n;
|
// paranoid sanity check, first two just can not happen ...
|
||||||
if ((taglen > n) || (b > n)) { // Can not happen ...
|
if ((taglen > n) || (b > n) || (n > USHRT_MAX)) {
|
||||||
rc = -EINVAL;
|
return -EINVAL;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Careful.
|
||||||
|
// We are using the stack to house the log buffer for speed reasons.
|
||||||
|
// If we malloc'd this buffer, we could get away without n's USHRT_MAX
|
||||||
|
// test above, but we would then required a max(n, USHRT_MAX) as
|
||||||
|
// truncating length argument to logbuf->log() below. Gain is protection
|
||||||
|
// of stack sanity and speedup, loss is truncated long-line content.
|
||||||
char newstr[n];
|
char newstr[n];
|
||||||
char *np = newstr;
|
char *np = newstr;
|
||||||
|
|
||||||
|
|
@ -763,8 +779,8 @@ int LogKlog::log(const char *buf, size_t len) {
|
||||||
np[b] = '\0';
|
np[b] = '\0';
|
||||||
|
|
||||||
// Log message
|
// Log message
|
||||||
rc = logbuf->log(LOG_ID_KERNEL, now, uid, pid, tid, newstr,
|
int rc = logbuf->log(LOG_ID_KERNEL, now, uid, pid, tid, newstr,
|
||||||
(n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
|
(unsigned short) n);
|
||||||
|
|
||||||
// notify readers
|
// notify readers
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue