From ee326d647b82d46897d98fcd109df2861abdb6e8 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Tue, 2 Sep 2025 07:07:01 -0700 Subject: [PATCH] Fuzzer issues (#1202) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/CLI/impl/App_inl.hpp | 2 +- include/CLI/impl/Config_inl.hpp | 12 ++++++++++-- tests/FuzzFailTest.cpp | 2 +- tests/fuzzFail/round_trip_custom24 | Bin 0 -> 141 bytes 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 tests/fuzzFail/round_trip_custom24 diff --git a/include/CLI/impl/App_inl.hpp b/include/CLI/impl/App_inl.hpp index 1e1d9f52..614805dd 100644 --- a/include/CLI/impl/App_inl.hpp +++ b/include/CLI/impl/App_inl.hpp @@ -1670,7 +1670,7 @@ CLI11_INLINE bool App::_parse_single_config(const ConfigItem &item, std::size_t throw ConfigError::NotConfigurable(item.fullname()); } if(op->empty()) { - std::vector buffer; // a buffer to use for copying an modifying inputs in a few cases + std::vector buffer; // a buffer to use for copying and modifying inputs in a few cases bool useBuffer{false}; if(item.multiline) { if(!op->get_inject_separator()) { diff --git a/include/CLI/impl/Config_inl.hpp b/include/CLI/impl/Config_inl.hpp index 19bb1587..97e3fd44 100644 --- a/include/CLI/impl/Config_inl.hpp +++ b/include/CLI/impl/Config_inl.hpp @@ -584,8 +584,16 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description, } } } - std::string value = - detail::ini_join(results, arraySeparator, arrayStart, arrayEnd, stringQuote, literalQuote); + std::string value; + if(opt->count() == 1 && results.size() == 2 && results.front() == "{}" && results.back() == "%%") { + // there is a catch to allow for {} to used as as string in the output + // it will append a sequence terminator to the output so the lexical conversion handles it + // correctly but that is meant for config files so when outputting for a config file we need to + // makes sure to get the correct output + value = "\"{}\""; + } else { + value = detail::ini_join(results, arraySeparator, arrayStart, arrayEnd, stringQuote, literalQuote); + } bool isDefault = false; if(value.empty() && default_also) { diff --git a/tests/FuzzFailTest.cpp b/tests/FuzzFailTest.cpp index 2433682d..5ce616eb 100644 --- a/tests/FuzzFailTest.cpp +++ b/tests/FuzzFailTest.cpp @@ -345,7 +345,7 @@ TEST_CASE("app_roundtrip_custom") { CLI::FuzzApp fuzzdata2; auto app = fuzzdata.generateApp(); auto app2 = fuzzdata2.generateApp(); - int index = GENERATE(range(1, 24)); + int index = GENERATE(range(1, 25)); auto parseData = loadFailureFile("round_trip_custom", index); diff --git a/tests/fuzzFail/round_trip_custom24 b/tests/fuzzFail/round_trip_custom24 new file mode 100644 index 0000000000000000000000000000000000000000..492ca4e75a3d31142c613b5fe28a32b3ea3cca78 GIT binary patch literal 141 zcmcCX%SlXEH#Br*V`Ed#x5>><$xO>kEh@IPWPpR>(j-Hpw1C@JAt3td)vL+L$v({1!YR@epER_U_XI&p_p b*9vjiI&oLm7Uvg~n3o0FmVw2qYZJHuI`S*6 literal 0 HcmV?d00001