liblog: print message payload of zero length

logcat will crash if the log message payload is of zero length. Side
effect of possible log messages from LogKlog in eng and userdebug
builds, or lower level logging calls.

NB: The referenced bug cited an example of this native crash, this
    does not fix the problem cited in the bug about the
    com.android.music shutdown.

Bug: 25774695
Change-Id: I5c7a6ad8db640ba9bc8d34fab04ba7cc2a9a426a
This commit is contained in:
Mark Salyzyn 2015-12-04 09:24:15 -08:00
parent beceb6ef53
commit d7bcf40ee6

View file

@ -500,14 +500,14 @@ int android_log_processLogBuffer(struct logger_entry *buf,
}
if (msgEnd == -1) {
/* incoming message not null-terminated; force it */
msgEnd = buf->len - 1;
msgEnd = buf->len - 1; /* may result in msgEnd < msgStart */
msg[msgEnd] = '\0';
}
entry->priority = msg[0];
entry->tag = msg + 1;
entry->message = msg + msgStart;
entry->messageLen = msgEnd - msgStart;
entry->messageLen = (msgEnd < msgStart) ? 0 : (msgEnd - msgStart);
return 0;
}