Skip to content

Commit

Permalink
fix a fuzzing issue from a string as a bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Jan 1, 2025
1 parent d2b331f commit 70eeff6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions include/CLI/impl/Option_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,29 @@ CLI11_INLINE int Option::_add_result(std::string &&result, std::vector<std::stri
int result_count = 0;
if((allow_extra_args_ || get_expected_max() > 1) && !result.empty() && result.front() == '[' &&
result.back() == ']') { // this is now a vector string likely from the default or user entry
if (result.size() >= 4 && result[1] == '[' && (*(result.end() - 2) == ']'))
{
//this is an escape clause for odd strings
std::string nstrs{ '[' };
bool duplicated{ true };
for (int ii = 2; ii < result.size() - 2; ii+=2)
{
if (result[ii] == result[ii + 1])
{
nstrs.push_back(result[ii]);
}
else {
duplicated=false;
break;
}
}
if (duplicated)
{
res.push_back(std::move(nstrs));
++result_count;
return result_count;
}
}
result.pop_back();
result.erase(result.begin());
bool skipSection{false};
Expand Down
4 changes: 2 additions & 2 deletions tests/FuzzFailTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ TEST_CASE("app_roundtrip_custom") {
CLI::FuzzApp fuzzdata2;
auto app = fuzzdata.generateApp();
auto app2 = fuzzdata2.generateApp();
int index = GENERATE(range(1, 3));
int index = GENERATE(range(1, 4));
std::string optionString, flagString;
auto parseData = loadFailureFile("round_trip_custom", index);
std::size_t pstring_start{0};
std::size_t pstring_start{0};
pstring_start = fuzzdata.add_custom_options(app.get(), parseData);

if(pstring_start > 0) {
Expand Down

0 comments on commit 70eeff6

Please sign in to comment.