Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42b54d83 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android Git Automerger
Browse files

am 1b3c4299: am 70212a40: Merge "Gracefully handle truncated log messages." into ics-mr1

* commit '1b3c4299':
  Gracefully handle truncated log messages.
parents 1941c913 1b3c4299
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -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;
}