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

Commit b1d150bc authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

liblog: logprint, error return and truncated data

android_log_processBinaryLogBuffer and android_log_processLogBuffer
error return should have message and messageLen fields set to zero,
or to a valid-but-truncated buffer so that we can discern the
difference.  This will resolve an issue with reporting content from
an uninitialized field in liblogcat should caller add --debug flag.

To enhance the debugging capability, truncated string events because
of the logger limits are provided rather than dropping the field, but
still with an error return.

Some minor coding style issues resolved. Add required, or remove
extraneous spaces.  Use C-style comments only.

Test: gtest liblog-unit-tests
Bug: 27405083
Bug: 35326290
Change-Id: I4a7ddd7278fb1c582f921e1ba10e0765fadb791b
parent 0ab93fdf
Loading
Loading
Loading
Loading
+29 −20
Original line number Original line Diff line number Diff line
@@ -20,9 +20,6 @@
#define HAVE_STRSEP
#define HAVE_STRSEP
#endif
#endif


//#ifndef __MINGW32__
//#include <arpa/inet.h>
//#endif
#include <assert.h>
#include <assert.h>
#include <ctype.h>
#include <ctype.h>
#include <errno.h>
#include <errno.h>
@@ -521,6 +518,9 @@ LIBLOG_ABI_PUBLIC int android_log_processLogBuffer(
        struct logger_entry *buf,
        struct logger_entry *buf,
        AndroidLogEntry *entry)
        AndroidLogEntry *entry)
{
{
    entry->message = NULL;
    entry->messageLen = 0;

    entry->tv_sec = buf->sec;
    entry->tv_sec = buf->sec;
    entry->tv_nsec = buf->nsec;
    entry->tv_nsec = buf->nsec;
    entry->uid = -1;
    entry->uid = -1;
@@ -829,7 +829,10 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData,
            eventData += 4;
            eventData += 4;
            eventDataLen -= 4;
            eventDataLen -= 4;


            if (eventDataLen < strLen) return -1;
            if (eventDataLen < strLen) {
                result = -1; /* mark truncated */
                strLen = eventDataLen;
            }


            if (cp && (strLen == 0)) {
            if (cp && (strLen == 0)) {
                /* reset the format if no content */
                /* reset the format if no content */
@@ -840,15 +843,18 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData,
                memcpy(outBuf, eventData, strLen);
                memcpy(outBuf, eventData, strLen);
                outBuf += strLen;
                outBuf += strLen;
                outBufLen -= strLen;
                outBufLen -= strLen;
            } else if (outBufLen > 0) {
            } else {
                if (outBufLen > 0) {
                    /* copy what we can */
                    /* copy what we can */
                    memcpy(outBuf, eventData, outBufLen);
                    memcpy(outBuf, eventData, outBufLen);
                    outBuf += outBufLen;
                    outBuf += outBufLen;
                    outBufLen -= outBufLen;
                    outBufLen -= outBufLen;
                goto no_room;
                }
                if (!result) result = 1; /* if not truncated, return no room */
            }
            }
            eventData += strLen;
            eventData += strLen;
            eventDataLen -= strLen;
            eventDataLen -= strLen;
            if (result != 0) goto bail;
            break;
            break;
        }
        }
    case EVENT_TYPE_LIST:
    case EVENT_TYPE_LIST:
@@ -991,13 +997,16 @@ no_room:
LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
        struct logger_entry *buf,
        struct logger_entry *buf,
        AndroidLogEntry *entry,
        AndroidLogEntry *entry,
        const EventTagMap *map __unused, // only on !__ANDROID__
        const EventTagMap *map __unused, /* only on !__ANDROID__ */
        char *messageBuf, int messageBufLen)
        char *messageBuf, int messageBufLen)
{
{
    size_t inCount;
    size_t inCount;
    uint32_t tagIndex;
    uint32_t tagIndex;
    const unsigned char* eventData;
    const unsigned char* eventData;


    entry->message = NULL;
    entry->messageLen = 0;

    entry->tv_sec = buf->sec;
    entry->tv_sec = buf->sec;
    entry->tv_nsec = buf->nsec;
    entry->tv_nsec = buf->nsec;
    entry->priority = ANDROID_LOG_INFO;
    entry->priority = ANDROID_LOG_INFO;
@@ -1217,7 +1226,7 @@ static size_t convertPrintable(char *p, const char *message, size_t messageLen)
                } else if (*message == '\b') {
                } else if (*message == '\b') {
                    strcpy(buf, "\\b");
                    strcpy(buf, "\\b");
                } else if (*message == '\t') {
                } else if (*message == '\t') {
                    strcpy(buf, "\t"); // Do not escape tabs
                    strcpy(buf, "\t"); /* Do not escape tabs */
                } else if (*message == '\v') {
                } else if (*message == '\v') {
                    strcpy(buf, "\\v");
                    strcpy(buf, "\\v");
                } else if (*message == '\f') {
                } else if (*message == '\f') {
@@ -1574,7 +1583,7 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
    nsec = entry->tv_nsec;
    nsec = entry->tv_nsec;
#if __ANDROID__
#if __ANDROID__
    if (p_format->monotonic_output) {
    if (p_format->monotonic_output) {
        // prevent convertMonotonic from being called if logd is monotonic
        /* prevent convertMonotonic from being called if logd is monotonic */
        if (android_log_clockid() != CLOCK_MONOTONIC) {
        if (android_log_clockid() != CLOCK_MONOTONIC) {
            struct timespec time;
            struct timespec time;
            convertMonotonic(&time, entry);
            convertMonotonic(&time, entry);
@@ -1648,7 +1657,7 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
            } else
            } else
#endif
#endif
            {
            {
                 // Not worth parsing package list, names all longer than 5
                 /* Not worth parsing package list, names all longer than 5 */
                 snprintf(uid, sizeof(uid), "%5d:", entry->uid);
                 snprintf(uid, sizeof(uid), "%5d:", entry->uid);
            }
            }
        } else {
        } else {