MCPcopy Create free account
hub / github.com/Taywee/args / LLVMFuzzerTestOneInput

Function LLVMFuzzerTestOneInput

fuzz/parse_schema_fuzzer.cpp:74–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72} // namespace
73
74extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
75{
76 FuzzedDataProvider fdp(data, size);
77
78 args::ArgumentParser parser("parse_schema_fuzzer", "typed value schema test");
79
80 args::HelpFlag help(parser, "help", "help", {'h', "help"});
81 args::Flag flag(parser, "flag", "flag", {'f', "flag"});
82 args::Flag once(parser, "once", "once", {'o'}, args::Options::Single);
83 args::CounterFlag count(parser, "count", "count", {'c', "count"});
84 args::ValueFlag<int> number(parser, "number", "number", {'n', "number"}, 0);
85 args::ValueFlag<double> ratio(parser, "ratio", "ratio", {"ratio"}, 0.0);
86 args::ValueFlag<std::string> label(parser, "label", "label", {'l', "label"}, std::string("x"));
87 args::ImplicitValueFlag<int> jobs(parser, "jobs", "jobs", {'j', "jobs"}, 0, 1);
88 args::ValueFlagList<int> numbers(parser, "nums", "nums", {'N', "nums"});
89 args::NargsValueFlag<std::string> pair(parser, "pair", "pair", {'P', "pair"}, args::Nargs(0, 2));
90 args::MapFlag<std::string, int> mode(parser, "mode", "mode", {'m', "mode"}, kModes);
91 args::MapFlagList<std::string, int> modes(parser, "modes", "modes", {"modes"}, kModes);
92 args::ValueFlag<std::string> required(parser, "req", "req", {"req"}, args::Options::Required);
93 args::Positional<std::string> src(parser, "src", "source");
94 args::MapPositional<std::string, int> posMode(parser, "posmode", "mapped positional", kModes);
95 args::PositionalList<std::string> dst(parser, "dst", "destinations");
96
97 const size_t tokenCount = fdp.ConsumeIntegralInRange<size_t>(1, 14);
98 std::vector<std::string> argv;
99 argv.reserve(tokenCount);
100 for (size_t i = 0; i < tokenCount; ++i)
101 {
102 if (fdp.ConsumeBool())
103 {
104 argv.emplace_back(kTokens[fdp.ConsumeIntegralInRange<size_t>(0, ArraySize(kTokens) - 1)]);
105 }
106 else
107 {
108 argv.emplace_back(fdp.ConsumeRandomLengthString(16));
109 }
110 }
111
112 // ParseArgs legitimately throws only args::Error subtypes; anything
113 // else escaping is a library bug and traps the fuzzer.
114 try
115 {
116 parser.ParseArgs(argv);
117 }
118 catch (const args::Error &)
119 {
120 }
121 catch (...)
122 {
123 __builtin_trap();
124 }
125
126 // -- Read back every typed result so getters and iterators instantiate ----
127 (void)count.Get();
128 if (number)
129 {
130 (void)*number;
131 }

Callers

nothing calls this directly

Calls 1

ArraySizeFunction · 0.70

Tested by

no test coverage detected