diff --git a/include/CLI/StringTools.hpp b/include/CLI/StringTools.hpp index 44f4a0e24..14fd1aee1 100644 --- a/include/CLI/StringTools.hpp +++ b/include/CLI/StringTools.hpp @@ -141,15 +141,15 @@ CLI11_INLINE std::ostream &format_aliases(std::ostream &out, const std::vector bool valid_first_char(T c) { - return ((c != '-') && (c != '!') && (c != ' ') && (c != '\n') && (c != '\0')); + return ((c != '-') && (static_cast(c) > 33)); // space and '!' not allowed } /// Verify following characters of an option template bool valid_later_char(T c) { // = and : are value separators, { has special meaning for option defaults, - // and \n and '\0' would just be annoying to deal with in many places allowing space here has too much potential for + // and control codes other than tab would just be annoying to deal with in many places allowing space here has too much potential for // inadvertent entry errors and bugs - return ((c != '=') && (c != ':') && (c != '{') && (c != ' ') && (c != '\n') && (c != '\0')); + return ((c != '=') && (c != ':') && (c != '{') && ((static_cast(c) > 32)||c=='\t')); } /// Verify an option/subcommand name diff --git a/include/CLI/impl/App_inl.hpp b/include/CLI/impl/App_inl.hpp index 4a582dd56..7251a5e49 100644 --- a/include/CLI/impl/App_inl.hpp +++ b/include/CLI/impl/App_inl.hpp @@ -371,13 +371,13 @@ CLI11_INLINE bool App::remove_option(Option *opt) { CLI11_INLINE App *App::add_subcommand(std::string subcommand_name, std::string subcommand_description) { if(!subcommand_name.empty() && !detail::valid_name_string(subcommand_name)) { if(!detail::valid_first_char(subcommand_name[0])) { - throw IncorrectConstruction("Subcommand name starts with invalid character, '!' and '-' are not allowed"); + throw IncorrectConstruction("Subcommand name starts with invalid character, '!' and '-' and control characters"); } for(auto c : subcommand_name) { if(!detail::valid_later_char(c)) { throw IncorrectConstruction(std::string("Subcommand name contains invalid character ('") + c + "'), all characters are allowed except" - "'=',':','{','}', and ' '"); + "'=',':','{','}', ' ', and control characters"); } } } diff --git a/tests/FuzzFailTest.cpp b/tests/FuzzFailTest.cpp index a4bf57ed9..1d2e15070 100644 --- a/tests/FuzzFailTest.cpp +++ b/tests/FuzzFailTest.cpp @@ -63,7 +63,7 @@ TEST_CASE("app_file_gen_fail") { CLI::FuzzApp fuzzdata; auto app = fuzzdata.generateApp(); - int index = GENERATE(range(1, 9)); + int index = GENERATE(range(1, 10)); std::string optionString, flagString; auto parseData = loadFailureFile("fuzz_app_file_fail", index); if(parseData.size() > 25) { diff --git a/tests/fuzzFail/fuzz_app_file_fail9 b/tests/fuzzFail/fuzz_app_file_fail9 new file mode 100644 index 000000000..1c8303c41 --- /dev/null +++ b/tests/fuzzFail/fuzz_app_file_fail9 @@ -0,0 +1 @@ +=oÿÿÿÿÿÿÿÿÿÿp--2vÿÿt ' Í-è- \ No newline at end of file