linux: Fix process start time computation

The process start time in ticks was being converted to an integer from a
temporary string that had gone out of scope by the time the conversion
was performed.

It was possible for a format error in /proc/pid/stat to go undetected
and result in a buffer overflow.

Bug: crashpad:30
Change-Id: I03566dda797bc1f23543bfffcfdb2c5ffe1eca66
Reviewed-on: https://chromium-review.googlesource.com/455378
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Mark Mentovai 2017-03-14 21:25:50 -04:00 committed by Commit Bot
parent bad4fd0011
commit 48781dc182

View File

@ -247,14 +247,19 @@ bool ProcessInfo::Initialize(pid_t pid) {
return false; return false;
} }
for (int index = 1; for (int index = 1; index < 21; ++index) {
index < 21 && stat_pos < stat_contents.size(); stat_pos = stat_contents.find(' ', stat_pos);
++index) { if (stat_pos == std::string::npos) {
stat_pos = stat_contents.find(" ", stat_pos); break;
}
++stat_pos; ++stat_pos;
} }
if (stat_pos >= stat_contents.size()) {
LOG(ERROR) << "format error";
return false;
}
const char* ticks_ptr = stat_contents.substr(stat_pos).c_str(); const char* ticks_ptr = &stat_contents[stat_pos];
// start time is in jiffies instead of clock ticks pre 2.6. // start time is in jiffies instead of clock ticks pre 2.6.
uint64_t ticks_after_boot; uint64_t ticks_after_boot;