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

Commit d44a5f84 authored by Tom Cherry's avatar Tom Cherry
Browse files

liblog: null terminate log_msg

Also, use LOGGER_ENTRY_MAX_LEN instead of sizeof(log_msg) for ensuring
that the read did not overflow, since sizeof(log_msg) is one byte
longer to allow for placing a null terminator already.

Bug: 148966104
Test: liblog unit tests
Change-Id: Id4fe8aa5da44e9d62f59b6541f157a4e7b038d07
parent e6211eb9
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -109,8 +109,8 @@ int android_logger_list_read(struct logger_list* logger_list, struct log_msg* lo
    return ret;
  }

  if (ret > (int)sizeof(*log_msg)) {
    ret = sizeof(*log_msg);
  if (ret > LOGGER_ENTRY_MAX_LEN) {
    ret = LOGGER_ENTRY_MAX_LEN;
  }

  if (ret < static_cast<int>(sizeof(log_msg->entry))) {
@@ -118,7 +118,7 @@ int android_logger_list_read(struct logger_list* logger_list, struct log_msg* lo
  }

  if (log_msg->entry.hdr_size < sizeof(log_msg->entry) ||
      log_msg->entry.hdr_size >= sizeof(struct log_msg) - sizeof(log_msg->entry)) {
      log_msg->entry.hdr_size >= LOGGER_ENTRY_MAX_LEN - sizeof(log_msg->entry)) {
    return -EINVAL;
  }

@@ -126,6 +126,8 @@ int android_logger_list_read(struct logger_list* logger_list, struct log_msg* lo
    return -EINVAL;
  }

  log_msg->buf[log_msg->entry.len + log_msg->entry.hdr_size] = '\0';

  return ret;
}