diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2011-10-26 18:40:39 -0700 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2011-10-26 18:59:42 -0700 |
| commit | a820a0e587b1f6be7283588b744cd33ba5723bdf (patch) | |
| tree | 528d3e17a5cc8a865a74543f34eb6f1f1f0a516c /liblog | |
| parent | 08dedcfd5cfeab526bb02382e4292f3150ed986f (diff) | |
| download | system_core-a820a0e587b1f6be7283588b744cd33ba5723bdf.tar.gz system_core-a820a0e587b1f6be7283588b744cd33ba5723bdf.tar.bz2 system_core-a820a0e587b1f6be7283588b744cd33ba5723bdf.zip | |
Gracefully handle truncated log messages.
Bug: 5522726
Change-Id: I8637c7da854ec1ecb321632c45ee9bc2edc94a67
Diffstat (limited to 'liblog')
| -rw-r--r-- | liblog/logprint.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/liblog/logprint.c b/liblog/logprint.c index daada5ad7..8366c94db 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -362,6 +362,9 @@ int android_log_processLogBuffer(struct logger_entry *buf, * starts at buf->msg+1 * msg * starts at buf->msg+1+len(tag)+1 + * + * The message may have been truncated by the kernel log driver. + * When that happens, we must null-terminate the message ourselves. */ if (buf->len < 3) { // An well-formed entry must consist of at least a priority @@ -370,21 +373,35 @@ int android_log_processLogBuffer(struct logger_entry *buf, return -1; } - int nullsFound = 0; + int msgStart = -1; + int msgEnd = -1; + int i; for (i = 1; i < buf->len; i++) { if (buf->msg[i] == '\0') { - nullsFound++; + if (msgStart == -1) { + msgStart = i + 1; + } else { + msgEnd = i; + break; + } } } - if (nullsFound != 2) { - fprintf(stderr, "+++ LOG: malformed log entry\n"); + + if (msgStart == -1) { + fprintf(stderr, "+++ LOG: malformed log message\n"); return -1; } + if (msgEnd == -1) { + // incoming message not null-terminated; force it + msgEnd = buf->len - 1; + buf->msg[msgEnd] = '\0'; + } + entry->priority = buf->msg[0]; entry->tag = buf->msg + 1; - entry->message = entry->tag + strlen(entry->tag) + 1; - entry->messageLen = strlen(entry->message); + entry->message = buf->msg + msgStart; + entry->messageLen = msgEnd - msgStart; return 0; } |
