| 18 | #include "../args.hxx" |
| 19 | |
| 20 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 21 | // Create a string from fuzzer input |
| 22 | std::string input(reinterpret_cast<const char*>(data), size); |
| 23 | |
| 24 | // Simulate command-line arguments |
| 25 | std::vector<std::string> args; |
| 26 | |
| 27 | // Parse input as space-separated arguments (simulate argv) |
| 28 | std::istringstream iss(input); |
| 29 | std::string arg; |
| 30 | while (iss >> arg) { |
| 31 | args.push_back(arg); |
| 32 | } |
| 33 | |
| 34 | if (args.empty()) { |
| 35 | return 0; // Nothing to parse |
| 36 | } |
| 37 | |
| 38 | // Build argv-style array |
| 39 | std::vector<char*> argv; |
| 40 | for (auto& a : args) { |
| 41 | argv.push_back(const_cast<char*>(a.c_str())); |
| 42 | } |
| 43 | |
| 44 | // Create argument parser |
| 45 | args::ArgumentParser parser("Fuzzer test", "Fuzzing argument parsing"); |
| 46 | |
| 47 | // Add various flag types to test |
| 48 | args::HelpFlag help(parser, "help", "Display help", {'h', "help"}); |
| 49 | args::Flag verbose(parser, "verbose", "Enable verbose", {'v', "verbose"}); |
| 50 | args::ValueFlag<std::string> name(parser, "name", "User name", {'n', "name"}); |
| 51 | args::ValueFlag<int> count(parser, "count", "Count value", {'c', "count"}); |
| 52 | args::Positional<std::string> positional(parser, "input", "Input file"); |
| 53 | |
| 54 | try { |
| 55 | // Parse the arguments - this is what we're fuzzing |
| 56 | parser.ParseArgs(static_cast<int>(argv.size()), argv.data()); |
| 57 | } catch (const args::Help&) { |
| 58 | // Help requested - normal behavior |
| 59 | return 0; |
| 60 | } catch (const args::ParseError& e) { |
| 61 | // Parse error - expected for malformed input |
| 62 | return 0; |
| 63 | } catch (const args::ValidationError& e) { |
| 64 | // Validation error - also expected |
| 65 | return 0; |
| 66 | } catch (const std::exception& e) { |
| 67 | // Any other exception is a potential bug |
| 68 | __builtin_trap(); // Signal fuzzer this is a crash |
| 69 | } |
| 70 | |
| 71 | return 0; // Success |
| 72 | } |
nothing calls this directly
no outgoing calls
no test coverage detected