Skip to content

Commit

Permalink
Fix how we disable tables in the fuzzer init method (#7419)
Browse files Browse the repository at this point in the history
The detach operation uses the DROP TABLE sql query to remove a table,
but this doesn't work with eponymous tables.
Use the "disable_tables" flag instead,
which prevents the initialization of the specified tables.
  • Loading branch information
Smjert authored Dec 21, 2021
1 parent d79a359 commit bd38031
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions osquery/main/harnesses/fuzz_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace osquery {

DECLARE_string(disable_tables);

std::set<std::string> kDisabledFuzzingTables = {
"file",
"hash",
Expand All @@ -27,22 +29,26 @@ int osqueryFuzzerInitialize(int* argc, char*** argv) {
osquery::registryAndPluginInit();
osquery::initDatabasePluginForTesting();

std::string disabled_tables;
for (auto table_name : kDisabledFuzzingTables) {
disabled_tables += table_name;
disabled_tables += ',';
}

if (!disabled_tables.empty()) {
disabled_tables.pop_back();
}

// Set the tables to disable in the flags; we cannot use the detach operation
FLAGS_disable_tables = disabled_tables;

auto* db = osquery::SQLiteDBManager::instance().get()->db();

// See https://www.sqlite.org/src/artifact/18af635f about limiting what
// effects the fuzzer triggers.
sqlite3_limit(db, SQLITE_LIMIT_VDBE_OP, 25000);
sqlite3_limit(db, SQLITE_LIMIT_LENGTH, 50000);

for (const auto& table_name : kDisabledFuzzingTables) {
osquery::PluginRequest r;
r["action"] = "detach";
r["table"] = table_name;

osquery::PluginResponse rsp;
osquery::Registry::get().call("sql", r, rsp);
}

FLAGS_minloglevel = 4;

return 0;
Expand Down

0 comments on commit bd38031

Please sign in to comment.