catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Ask read() for at most SSIZE_MAX bytes in PipeReader::Read
- Commit
7c3b73b14a3f0714c8eca3ad1a69bc1963ae773d- Author
- Leitwolf11 ·
- Parents
7ff85d401d6f
Changes
extras/catch_amalgamated.cpp | 8 +++++++- src/Progmasoft/Runner/Process.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/extras/catch_amalgamated.cpp b/extras/catch_amalgamated.cpp index 475c5ea8..e09c8a56 100644 --- a/extras/catch_amalgamated.cpp +++ b/extras/catch_amalgamated.cpp @@ -15678,6 +15678,7 @@ namespace Progmasoft::Catch3::Runner #include <cstdlib> #include <cstring> #include <iterator> +#include <limits> #include <mutex> #include <string_view> #include <thread> @@ -16165,9 +16166,14 @@ namespace Progmasoft::Catch3::Runner } return static_cast<std::int64_t>(read); #else + // read() leaves a request above SSIZE_MAX to the implementation, so + // one call asks for at most that much and never more than the buffer. + const auto request = std::min<std::size_t>( + size, + static_cast<std::size_t>(std::numeric_limits<ssize_t>::max())); while (true) { - const auto count = read(Descriptor(handle_), buffer, size); + const auto count = read(Descriptor(handle_), buffer, request); if (count >= 0) { return static_cast<std::int64_t>(count); diff --git a/src/Progmasoft/Runner/Process.cpp b/src/Progmasoft/Runner/Process.cpp index 52c285e0..b81c121a 100644 --- a/src/Progmasoft/Runner/Process.cpp +++ b/src/Progmasoft/Runner/Process.cpp @@ -6,6 +6,7 @@ #include <cstdlib> #include <cstring> #include <iterator> +#include <limits> #include <mutex> #include <string_view> #include <thread> @@ -494,9 +495,14 @@ namespace Progmasoft::Catch3::Runner } return static_cast<std::int64_t>(read); #else + // read() leaves a request above SSIZE_MAX to the implementation, so + // one call asks for at most that much and never more than the buffer. + const auto request = std::min<std::size_t>( + size, + static_cast<std::size_t>(std::numeric_limits<ssize_t>::max())); while (true) { - const auto count = read(Descriptor(handle_), buffer, size); + const auto count = read(Descriptor(handle_), buffer, request); if (count >= 0) { return static_cast<std::int64_t>(count);