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

Commit 157f2725 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Fix null pointer dereference.

In the function dump_thread_info, if /proc/<PID>/comm is unreadable, then
threadname will be used in a strncmp causing a crash. The fix is to
avoid the check if threadname is null.

Bug: 28615417
(cherry picked from commit 039976e5)

Change-Id: I1e61431b1549ecfdc49a72cbf193a364069cda79
parent d4946658
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -201,7 +201,7 @@ static void dump_signal_info(log_t* log, pid_t tid, int signal, int si_code) {
static void dump_thread_info(log_t* log, pid_t pid, pid_t tid) {
static void dump_thread_info(log_t* log, pid_t pid, pid_t tid) {
  char path[64];
  char path[64];
  char threadnamebuf[1024];
  char threadnamebuf[1024];
  char* threadname = NULL;
  char* threadname = nullptr;
  FILE *fp;
  FILE *fp;


  snprintf(path, sizeof(path), "/proc/%d/comm", tid);
  snprintf(path, sizeof(path), "/proc/%d/comm", tid);
@@ -217,13 +217,13 @@ static void dump_thread_info(log_t* log, pid_t pid, pid_t tid) {
  }
  }
  // Blacklist logd, logd.reader, logd.writer, logd.auditd, logd.control ...
  // Blacklist logd, logd.reader, logd.writer, logd.auditd, logd.control ...
  static const char logd[] = "logd";
  static const char logd[] = "logd";
  if (!strncmp(threadname, logd, sizeof(logd) - 1)
  if (threadname != nullptr && !strncmp(threadname, logd, sizeof(logd) - 1)
      && (!threadname[sizeof(logd) - 1] || (threadname[sizeof(logd) - 1] == '.'))) {
      && (!threadname[sizeof(logd) - 1] || (threadname[sizeof(logd) - 1] == '.'))) {
    log->should_retrieve_logcat = false;
    log->should_retrieve_logcat = false;
  }
  }


  char procnamebuf[1024];
  char procnamebuf[1024];
  char* procname = NULL;
  char* procname = nullptr;


  snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
  snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
  if ((fp = fopen(path, "r"))) {
  if ((fp = fopen(path, "r"))) {