Skip to content

Commit 70eeff6

Browse files
committed
fix a fuzzing issue from a string as a bracket
1 parent d2b331f commit 70eeff6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Diff for: include/CLI/impl/Option_inl.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,29 @@ CLI11_INLINE int Option::_add_result(std::string &&result, std::vector<std::stri
664664
int result_count = 0;
665665
if((allow_extra_args_ || get_expected_max() > 1) && !result.empty() && result.front() == '[' &&
666666
result.back() == ']') { // this is now a vector string likely from the default or user entry
667+
if (result.size() >= 4 && result[1] == '[' && (*(result.end() - 2) == ']'))
668+
{
669+
//this is an escape clause for odd strings
670+
std::string nstrs{ '[' };
671+
bool duplicated{ true };
672+
for (int ii = 2; ii < result.size() - 2; ii+=2)
673+
{
674+
if (result[ii] == result[ii + 1])
675+
{
676+
nstrs.push_back(result[ii]);
677+
}
678+
else {
679+
duplicated=false;
680+
break;
681+
}
682+
}
683+
if (duplicated)
684+
{
685+
res.push_back(std::move(nstrs));
686+
++result_count;
687+
return result_count;
688+
}
689+
}
667690
result.pop_back();
668691
result.erase(result.begin());
669692
bool skipSection{false};

Diff for: tests/FuzzFailTest.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ TEST_CASE("app_roundtrip_custom") {
267267
CLI::FuzzApp fuzzdata2;
268268
auto app = fuzzdata.generateApp();
269269
auto app2 = fuzzdata2.generateApp();
270-
int index = GENERATE(range(1, 3));
270+
int index = GENERATE(range(1, 4));
271271
std::string optionString, flagString;
272272
auto parseData = loadFailureFile("round_trip_custom", index);
273-
std::size_t pstring_start{0};
273+
std::size_t pstring_start{0};
274274
pstring_start = fuzzdata.add_custom_options(app.get(), parseData);
275275

276276
if(pstring_start > 0) {

0 commit comments

Comments
 (0)