Skip to content

Commit

Permalink
Fix potential write outside of array in dynamic_thread_pool_group's n…
Browse files Browse the repository at this point in the history
…ative Linux implementation.
  • Loading branch information
ned14 committed Jul 19, 2021
1 parent 4def09a commit d867bd6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/llfio/v2.0/detail/impl/dynamic_thread_pool_group.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ namespace detail
int fd = ::open(path, O_RDONLY);
if(-1 == fd)
{
threadearlyexited:
// Thread may have exited since we last populated
if(item->blocked_since == std::chrono::steady_clock::time_point())
{
Expand All @@ -863,7 +864,11 @@ namespace detail
char buffer[1024];
auto bytesread = ::read(fd, buffer, sizeof(buffer));
::close(fd);
buffer[std::max((size_t) bytesread, sizeof(buffer) - 1)] = 0;
if(bytesread <= 0)
{
goto threadearlyexited;
}
buffer[std::min((size_t) bytesread, sizeof(buffer) - 1)] = 0;
char state = 0;
unsigned long majflt = 0, utime = 0, stime = 0;
sscanf(buffer, "%*d %*s %c %*d %*d %*d %*d %*d %*u %*u %*u %lu %*u %lu %lu", &state, &majflt, &utime, &stime);
Expand Down

0 comments on commit d867bd6

Please sign in to comment.