From d7bcf40ee636e6ad5b79f4601ffad5282f543ca1 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Fri, 4 Dec 2015 09:24:15 -0800 Subject: [PATCH] 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 --- liblog/logprint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liblog/logprint.c b/liblog/logprint.c index ad52a8119..40e13f435 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -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; }