Fix some minor fuzzing issues. (#1138)

One in the fuzz check handling of NaN's and a pathway to generate a
HorribleError.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top
2025-03-11 18:21:46 -07:00
committed by GitHub
parent f871b625ee
commit 2d79205521
6 changed files with 63 additions and 6 deletions

View File

@@ -306,14 +306,13 @@ TEST_CASE("fuzz_config_modifier_test1") {
CHECK(opt3->get_multi_option_policy() == CLI::MultiOptionPolicy::Sum);
}
// this test uses the same tests as above just with a full roundtrip test
// this test enables the custom option creation operation
TEST_CASE("app_roundtrip_custom") {
CLI::FuzzApp fuzzdata;
CLI::FuzzApp fuzzdata2;
auto app = fuzzdata.generateApp();
auto app2 = fuzzdata2.generateApp();
int index = GENERATE(range(1, 4));
std::string optionString, flagString;
int index = GENERATE(range(1, 5));
auto parseData = loadFailureFile("round_trip_custom", index);
std::size_t pstring_start{0};
pstring_start = fuzzdata.add_custom_options(app.get(), parseData);
@@ -335,3 +334,43 @@ TEST_CASE("app_roundtrip_custom") {
auto result = fuzzdata2.compare(fuzzdata);
CHECK(result);
}
// this test
TEST_CASE("app_roundtrip_parse_normal_fail") {
// this is mostly checking that no unexpected errors occur
// like HorribleErrors
CLI::FuzzApp fuzzdata;
auto app = fuzzdata.generateApp();
int index = GENERATE(range(1, 3));
std::string optionString, flagString;
auto parseData = loadFailureFile("parse_fail_check", index);
std::size_t pstring_start{0};
pstring_start = fuzzdata.add_custom_options(app.get(), parseData);
try {
if(pstring_start > 0) {
app->parse(parseData.substr(pstring_start));
} else {
app->parse(parseData);
}
} catch(const CLI::HorribleError & /*he*/) {
CHECK(false);
return;
} catch(const CLI::ParseError & /*e*/) {
CHECK(true);
return;
}
try {
// 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);
app->parse_from_stream(out);
} catch(const CLI::HorribleError & /*he*/) {
CHECK(false);
return;
} catch(const CLI::ParseError & /*e*/) {
CHECK(false);
return;
}
}

View File

@@ -0,0 +1 @@
'--sub1.!-vA '

Binary file not shown.

View File

@@ -0,0 +1 @@
--vC