Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2021-07-19 19:43:22 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2021-07-19 19:43:22 +0300
commitd867bd612097979ca40b07852abbf7332538ab98 (patch)
tree32e8a730148759bc817db7b9cc3a5a8dc2e51429
parent4def09a17a65ee4b4ecbd6e5815be5493edc06f7 (diff)
Fix potential write outside of array in dynamic_thread_pool_group's native Linux implementation.
-rw-r--r--include/llfio/v2.0/detail/impl/dynamic_thread_pool_group.ipp7
1 files changed, 6 insertions, 1 deletions
diff --git a/include/llfio/v2.0/detail/impl/dynamic_thread_pool_group.ipp b/include/llfio/v2.0/detail/impl/dynamic_thread_pool_group.ipp
index 4192306c..a476496b 100644
--- a/include/llfio/v2.0/detail/impl/dynamic_thread_pool_group.ipp
+++ b/include/llfio/v2.0/detail/impl/dynamic_thread_pool_group.ipp
@@ -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())
{
@@ -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);