diff options
author | Kenny Root <kroot@google.com> | 2011-09-30 17:10:14 -0700 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2011-10-03 14:14:41 -0700 |
commit | 4bf3c02e026077d14a4512c7c2f71937da3c2d50 (patch) | |
tree | 7fd7c515c75cc0f64d9be5351be46f7d767e5794 /liblog | |
parent | e5de9ee4915bafd7f31a96260613d8b93aba8351 (diff) | |
download | system_core-4bf3c02e026077d14a4512c7c2f71937da3c2d50.zip system_core-4bf3c02e026077d14a4512c7c2f71937da3c2d50.tar.gz system_core-4bf3c02e026077d14a4512c7c2f71937da3c2d50.tar.bz2 |
Add checking for log entry format
The log tag may be zero length if corrupted, so check for this
condition.
Change-Id: I7616226dabe78a85859b0ab53aca08f734dbdd84
Diffstat (limited to 'liblog')
-rw-r--r-- | liblog/logprint.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/liblog/logprint.c b/liblog/logprint.c index 4c5b3e5..59fed9b 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -350,16 +350,28 @@ static inline char * strip_end(char *str) int android_log_processLogBuffer(struct logger_entry *buf, AndroidLogEntry *entry) { - size_t tag_len; - entry->tv_sec = buf->sec; entry->tv_nsec = buf->nsec; entry->priority = buf->msg[0]; entry->pid = buf->pid; entry->tid = buf->tid; + + /* + * format: <priority:1><tag:N>\0<message:N>\0 + * + * tag str + * starts at msg+1 + * msg + * starts at msg+1+len(tag)+1 + */ entry->tag = buf->msg + 1; - tag_len = strlen(entry->tag); - entry->messageLen = buf->len - tag_len - 3; + const size_t tag_len = strlen(entry->tag); + const size_t preambleAndNullLen = tag_len + 3; + if (buf->len <= preambleAndNullLen) { + fprintf(stderr, "+++ LOG: entry corrupt or truncated\n"); + return -1; + } + entry->messageLen = buf->len - preambleAndNullLen; entry->message = entry->tag + tag_len + 1; return 0; |