Correct arguments parsing

This commit is contained in:
Alexey Milovidov 2024-03-18 02:35:32 +01:00
parent 1a61da1bae
commit 2eb7de859d
3 changed files with 10 additions and 13 deletions

View File

@ -878,6 +878,11 @@ void LocalServer::processOptions(const OptionsDescription &, const CommandLineOp
void LocalServer::readArguments(int argc, char ** argv, Arguments & common_arguments, std::vector<Arguments> &, std::vector<Arguments> &)
{
#if defined(FUZZING_MODE)
if (argc)
fuzzer_args.push_back(argv[0]);
#endif
for (int arg_num = 1; arg_num < argc; ++arg_num)
{
std::string_view arg = argv[arg_num];
@ -916,8 +921,7 @@ void LocalServer::readArguments(int argc, char ** argv, Arguments & common_argum
else if (arg == "--")
{
#if defined(FUZZING_MODE)
fuzzer_argc = 1 + argc - arg_num;
fuzzer_argv = argv + arg_num;
fuzzer_args.insert(fuzzer_args.end(), &argv[arg_num + 1], &argv[argc]);
break;
#endif
}
@ -926,14 +930,6 @@ void LocalServer::readArguments(int argc, char ** argv, Arguments & common_argum
common_arguments.emplace_back(arg);
}
}
#if defined(FUZZING_MODE)
if (!fuzzer_argc)
{
fuzzer_argc = 1;
fuzzer_argv = argv;
}
#endif
}
}

View File

@ -2638,6 +2638,9 @@ ClientBase * app;
void ClientBase::runLibFuzzer()
{
app = this;
int fuzzer_argc = fuzzer_args.size();
char ** fuzzer_argv = fuzzer_args.data();
LLVMFuzzerRunDriver(&fuzzer_argc, &fuzzer_argv, [](const uint8_t * data, size_t size)
{
try

View File

@ -79,9 +79,7 @@ protected:
void runNonInteractive();
#if defined(FUZZING_MODE)
int fuzzer_argc = 0;
char ** fuzzer_argv = nullptr;
std::vector<char *> fuzzer_args;
void runLibFuzzer();
#endif