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
Bound three string and XML reads that analysis flagged
- Commit
79f624d693b4fc3167c239c3eca47c858799333f- Author
- Leitwolf11 ·
- Parents
6750f61c28be
Changes
src/Progmasoft/Runner/Process.cpp | 7 ++++++- tests/SelfTest/UsageTests/Generators.tests.cpp | 4 ++-- tests/TestScripts/testBazelReporter.py | 9 ++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Progmasoft/Runner/Process.cpp b/src/Progmasoft/Runner/Process.cpp index e3b0997b..b858d1e6 100644 --- a/src/Progmasoft/Runner/Process.cpp +++ b/src/Progmasoft/Runner/Process.cpp @@ -1286,7 +1286,12 @@ namespace Progmasoft::Catch3::Runner std::string buffer(size, '\0'); if (_NSGetExecutablePath(buffer.data(), &size) == 0) { - buffer.resize(std::strlen(buffer.c_str())); + // The path ends at its first NUL, never past the buffer. + const auto end = buffer.find('\0'); + if (end != std::string::npos) + { + buffer.resize(end); + } auto canonical = std::filesystem::weakly_canonical(buffer, error); return error ? std::filesystem::path{ buffer } : canonical; } diff --git a/tests/SelfTest/UsageTests/Generators.tests.cpp b/tests/SelfTest/UsageTests/Generators.tests.cpp index 655c4608..77ffde8d 100644 --- a/tests/SelfTest/UsageTests/Generators.tests.cpp +++ b/tests/SelfTest/UsageTests/Generators.tests.cpp @@ -12,7 +12,7 @@ #include <Progmasoft/Catch3/Generators/Random.hpp> #include <Progmasoft/Catch3/Generators/Range.hpp> -#include <cstring> +#include <string_view> // Generators and sections can be nested freely @@ -62,7 +62,7 @@ TEST_CASE("tables", "[generators]") { tuple_type{"etc...", 6} })); - REQUIRE(strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data))); + REQUIRE(std::string_view(std::get<0>(data)).size() == static_cast<size_t>(std::get<1>(data))); } diff --git a/tests/TestScripts/testBazelReporter.py b/tests/TestScripts/testBazelReporter.py index 62600a39..f91e7b0f 100644 --- a/tests/TestScripts/testBazelReporter.py +++ b/tests/TestScripts/testBazelReporter.py @@ -56,7 +56,14 @@ if ret.returncode != 42: exit(1) try: - tree = ET.parse(xml_out_path) + with open(xml_out_path, 'r', encoding='utf-8') as report: + text = report.read() + # A JUnit report has no document type, so it declares no entities: one + # that does is rejected before parsing, and no entity is ever expanded. + if '<!DOCTYPE' in text or '<!ENTITY' in text: + print("The report declares a document type: '{}'".format(xml_out_path)) + exit(2) + tree = ET.ElementTree(ET.fromstring(text)) except ET.ParseError as ex: print("Invalid XML: '{}'".format(ex)) raise