mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
Fuzz fail (#1097)
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
BIN
tests/fuzzFail/round_trip_custom1
Normal file
BIN
tests/fuzzFail/round_trip_custom1
Normal file
Binary file not shown.
1
tests/fuzzFail/round_trip_custom2
Normal file
1
tests/fuzzFail/round_trip_custom2
Normal file
@@ -0,0 +1 @@
|
||||
--vM=[ー
|
||||
Reference in New Issue
Block a user