Skip to content

Commit

Permalink
fix additional fuzzing test to allow for file based array arguments o…
Browse files Browse the repository at this point in the history
…f flags with disable flag override
  • Loading branch information
phlptp committed Nov 5, 2023
1 parent 4c98bd8 commit 78b97d5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
44 changes: 42 additions & 2 deletions include/CLI/impl/App_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ CLI11_NODISCARD CLI11_INLINE std::string App::help(std::string prev, AppFormatMo
CLI11_NODISCARD CLI11_INLINE std::string App::version() const {
std::string val;
if(version_ptr_ != nullptr) {
auto rv = version_ptr_->results();
// copy the results for reuse later
results_t rv = version_ptr_->results();
version_ptr_->clear();
version_ptr_->add_result("true");
try {
Expand Down Expand Up @@ -1479,7 +1480,46 @@ CLI11_INLINE bool App::_parse_single_config(const ConfigItem &item, std::size_t
if(op->get_items_expected_max() > 1) {
throw ArgumentMismatch::AtMost(item.fullname(), op->get_items_expected_max(), item.inputs.size());
}
throw ConversionError::TooManyInputsFlag(item.fullname());
if (op->get_disable_flag_override())
{
for (const auto& res : item.inputs)
{
bool valid_value{false};
if (op->default_flag_values_.empty())
{
if (res == "true" || res == "false" || res == "1" || res == "0") {
valid_value=true;
}
}
else
{
for (const auto& valid_res : op->default_flag_values_)
{
if (valid_res.second == res)
{
valid_value=true;
break;
}
}

}

if (valid_value)
{
op->add_result(res);
}
else
{
throw InvalidError("invalid flag argument given");
}
}
return true;
}
else
{
throw ConversionError::TooManyInputsFlag(item.fullname());
}

}
}
op->add_result(item.inputs);
Expand Down
3 changes: 2 additions & 1 deletion include/CLI/impl/Config_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,
}
}
if(!valid) {
throw;
value = detail::ini_join(
opt->results(), arraySeparator, arrayStart, arrayEnd, stringQuote, characterQuote);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FuzzFailTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST_CASE("app_file_gen_fail") {
CLI::FuzzApp fuzzdata;
auto app = fuzzdata.generateApp();

int index = GENERATE(range(1, 4));
int index = GENERATE(range(1, 5));
std::string optionString, flagString;
auto parseData = loadFailureFile("fuzz_app_file_fail", index);
if(parseData.size() > 25) {
Expand Down
1 change: 1 addition & 0 deletions tests/fuzzFail/fuzz_app_file_fail4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-ccaaaa

0 comments on commit 78b97d5

Please sign in to comment.