fix failing fuzz case involving binary string with a '\x' in it.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top
2024-11-30 07:13:49 -08:00
committed by GitHub
parent 8260578fd2
commit 063b2c911c
8 changed files with 98 additions and 7 deletions

View File

@@ -260,3 +260,33 @@ TEST_CASE("fuzz_config_test1") {
CHECK(app->get_option_no_throw("--new_flag") != nullptr);
CHECK(app->get_option_no_throw("--new_vector") != nullptr);
}
// this test uses the same tests as above just with a full roundtrip test
TEST_CASE("app_roundtrip_custom") {
CLI::FuzzApp fuzzdata;
CLI::FuzzApp fuzzdata2;
auto app = fuzzdata.generateApp();
auto app2 = fuzzdata2.generateApp();
int index = GENERATE(range(1, 3));
std::string optionString, flagString;
auto parseData = loadFailureFile("round_trip_custom", index);
std::size_t pstring_start{0};
pstring_start = fuzzdata.add_custom_options(app.get(), parseData);
if(pstring_start > 0) {
app->parse(parseData.substr(pstring_start));
} else {
app->parse(parseData);
}
// should be able to write the config to a file and read from it again
std::string configOut = app->config_to_str();
app->clear();
std::stringstream out(configOut);
if(pstring_start > 0) {
fuzzdata2.add_custom_options(app2.get(), parseData);
}
app2->parse_from_stream(out);
auto result = fuzzdata2.compare(fuzzdata);
CHECK(result);
}

View File

@@ -301,6 +301,42 @@ TEST_CASE("StringTools: binaryEscapseConversion2", "[helpers]") {
CHECK(rstring == testString);
}
TEST_CASE("StringTools: binaryEscapseConversion_withX", "[helpers]") {
std::string testString("hippy\\x35mm\\XF3_helpX26fox19");
testString.push_back(0);
testString.push_back(0);
testString.push_back(0);
testString.push_back(56);
testString.push_back(-112);
testString.push_back(-112);
testString.push_back(39);
testString.push_back(97);
std::string estring = CLI::detail::binary_escape_string(testString);
CHECK(CLI::detail::is_binary_escaped_string(estring));
std::string rstring = CLI::detail::extract_binary_string(estring);
CHECK(rstring == testString);
}
TEST_CASE("StringTools: binaryEscapseConversion_withBrackets", "[helpers]") {
std::string vstr = R"raw('B"([\xb0\x0a\xb0/\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0])"')raw";
std::string testString("[");
testString.push_back(-80);
testString.push_back('\n');
testString.push_back(-80);
testString.push_back('/');
for(int ii = 0; ii < 13; ++ii) {
testString.push_back(-80);
}
testString.push_back(']');
std::string estring = CLI::detail::binary_escape_string(testString);
CHECK(CLI::detail::is_binary_escaped_string(estring));
CHECK(estring == vstr);
std::string rstring = CLI::detail::extract_binary_string(estring);
CHECK(rstring == testString);
}
TEST_CASE("StringTools: binaryStrings", "[helpers]") {
std::string rstring = "B\"()\"";
CHECK(CLI::detail::extract_binary_string(rstring).empty());

Binary file not shown.

View File

@@ -0,0 +1 @@
--vM=[ー