diff --git a/src/linux.cc b/src/linux.cc index 12532514..94498616 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -1014,7 +1014,7 @@ int update_stat(void) { cpu[idx].cpu_last_total = cpu[idx].cpu_total; cpu[idx].cpu_last_active_total = cpu[idx].cpu_active_total; - for (i = samples - 1; i > 0; i--) { + for (i = samples - 1; i > 0 && i < CPU_SAMPLE_COUNT; i--) { cpu[idx].cpu_val[i] = cpu[idx].cpu_val[i - 1]; } } diff --git a/src/mail.cc b/src/mail.cc index 22eaf276..138c312e 100644 --- a/src/mail.cc +++ b/src/mail.cc @@ -814,7 +814,10 @@ void imap_cb::work() { } if (buf != nullptr) { // back up until we reach '*' - while (buf >= recvbuf && buf[0] != '*') { buf--; } + while (buf >= recvbuf && buf < (recvbuf + MAXDATASIZE) - 1 && + buf[0] != '*') { + buf--; + } if (sscanf(buf, "* %lu EXISTS\r\n", &messages) == 1) { std::lock_guard lock(result_mutex); if (result.messages != messages) { @@ -831,7 +834,10 @@ void imap_cb::work() { } if (buf != nullptr) { // back up until we reach '*' - while (buf >= recvbuf && buf[0] != '*') { buf--; } + while (buf >= recvbuf && buf < (recvbuf + MAXDATASIZE) - 1 && + buf[0] != '*') { + buf--; + } if (sscanf(buf, "* %lu RECENT\r\n", &recent) != 1) { recent = 0; } } }