Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/extras/catch_amalgamated.cpp
diff options
context:
space:
mode:
authorLeitwolf112026-11-17 19:00:44 +0300
committerLeitwolf112026-11-17 19:00:44 +0300
commit7c3b73b14a3f0714c8eca3ad1a69bc1963ae773d (patch)
treeff49cb6e7f90b671577993202249f207cfc99b6d /extras/catch_amalgamated.cpp
parent7ff85d401d6f7f2d37fc0566f346a521a9bb7cee (diff)
downloadcatch3-fix/pipe-read-limit.tar.gz
Ask read() for at most SSIZE_MAX bytes in PipeReader::Readfix/pipe-read-limit
POSIX leaves a read() request above SSIZE_MAX to the implementation, and the count it returns could not then be told from an error. The POSIX branch of PipeReader::Read now asks for the smaller of the buffer size and SSIZE_MAX, as the Windows branch already limits one ReadFile call. The caller sees no change: a short read was always possible, and the reader loops until the pipe ends. The single-file distribution is regenerated from the sources. Checked: bazelisk test //... (3 of 3 pass), bazelisk run //tools:amalgamate -- --check, clang-format dry-run with -Werror.
Diffstat (limited to 'extras/catch_amalgamated.cpp')
-rw-r--r--extras/catch_amalgamated.cpp8
1 files changed, 7 insertions, 1 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);