osquery-1/osquery/main/harnesses/fuzz_config.cpp
Tom Ritter 1642382ff9 Move fuzzing harness to a new directory and refactor fuzzing constants (#5909) (#5910)
This commit creates a new osquery/main/harnesses directory and moves fuzz-config there.

It removes OSQUERY_FUZZ for a new option OSQUERY_ENABLE_FUZZER_SANITIZERS
It creates a new option OSQUERY_ENABLE_ADDRESS_SANITIZER

The following behaviors are intended:

OSQUERY_BUILD_TESTS=ON will build the fuzzing harness. This configuration is not
intended for fuzzing purposes. OSQUERY_ENABLE_FUZZER_SANITIZERS=ON will also build
the fuzzing harness. However if this variable is true, it also requires
OSQUERY_ENABLE_ADDRESS_SANITIZER=ON and either CMAKE_BUILD_TYPE=Release or
RelWithDebInfo This configuration is actually intended for fuzzing.
2019-10-20 14:09:45 -04:00

38 lines
1011 B
C++

/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed in accordance with the terms specified in
* the LICENSE file found in the root directory of this source tree.
*/
#include <osquery/config/config.h>
#include <osquery/database.h>
#include <osquery/logger.h>
#include <osquery/registry.h>
#include <osquery/sql.h>
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
osquery::registryAndPluginInit();
osquery::DatabasePlugin::setAllowOpen(true);
osquery::Registry::get().setActive("database", "ephemeral");
osquery::DatabasePlugin::initPlugin().ok();
osquery::PluginRequest r;
r["action"] = "detach";
r["table"] = "file";
osquery::PluginResponse rsp;
osquery::Registry::get().call("sql", r, rsp);
FLAGS_minloglevel = 4;
return 0;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::string q((const char*)data, size);
osquery::Config::get().update({{"fuzz", q}});
return 0;
}